PHP code example of nilz / money

1. Go to this page and download the library: Download nilz/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/ */

    

nilz / money example snippets


use Nilz\Money\Money;
use Nilz\Money\Currency\ISO4217Currency;

$money = new Money(420, new ISO4217Currency('EUR'));

$money = Money::fromDefaultUnitAmount('4.20', 'EUR');


//420
echo $money->getAmount();

//4.20
echo $money->getDefaultUnitAmount();

//4,20 €
echo $money->getFormattedAmount('de_DE');



$a = Money::fromDefaultUnitAmount('4.20', 'EUR');
$b = Money::fromDefaultUnitAmount('2.10', 'EUR');

$c = $a->add($b);

//6.30
echo $c->getAmount();

//4.20
echo $a->getAmount();

//2.10
echo $b->getAmount();



$a = Money::fromDefaultUnitAmount('4.20', 'EUR');
$b = Money::fromDefaultUnitAmount('2.10', 'EUR');

$a->subtract($b);

$a->multiply(1.2);
$a->divide(1.2);


use Nilz\Money\Currency\Currency;

//alpha3 code, factor for smallest unit representation, decimal digits to round two
$money = new Money(420, new Currency('EUR', 100, 2));