PHP code example of assimtech / money

1. Go to this page and download the library: Download assimtech/money library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

assimtech / money example snippets


$usd = new Assimtech\Money\Currency('USD');
echo (string)$usd; // Outputs USD
echo $usd->getFractionDigits(); // Outputs 2

$jpy = new Assimtech\Money\Currency('JPY');
echo $jpy->getFractionDigits(); // Outputs 0

$iqd = new Assimtech\Money\Currency('IQD');
echo $iqd->getFractionDigits(); // Outputs 3

// assuming Locale is en-US
$money = new Money(pi(), $usd);
echo (string)$money; // Outputs 3.14 USD
echo $money->getFormattedAmount(); // Outputs 3.14
echo $money->getFormattedAmount('de-DE'); // Outputs 3,14

$accountant = new Assimtech\Money\Accountant();

$threeUSD = $accountant->add($oneUSD, $twoUSD);

$sixUSD = $accountant->subtract($tenUSD, $fourUSD);

$eightUSD = $accountant->multiply($fourUSD, 2);

$threeUSD = $accountant->divide($nineUSD, 3);

$sixUSD = $accountant->sum(array(
    $oneUSD,
    $twoUSD,
    $threeUSD,
));