PHP code example of lukam / money
1. Go to this page and download the library: Download lukam/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/ */
lukam / money example snippets
use Money;
$euro = Money::eur(100);
$tenEuro = $euro + Money::eur(900);
print($tenEuro->format()); // 10,00 €
$shares = $tenEuro->allocate([1,1,1]);
print($shares[0]->format()); //3,34 €
print($shares[1]->format()); //3,33 €
print($shares[2]->format()); //3,33 €
$euro = Money::eur(100);
print($euro->getAmount()); // 100
$fiveEuro = Money::eur(500);
$tenEuro = $fiveEuro->add($fiveEuro);
$fiveEuro = Money::eur(500);
$zeroEuro = $fiveEuro->subtract($fiveEuro);
$fiveEuro = Money::eur(500);
$tenEuro = $fiveEuro->multiply(2);
$tenEuro = Money::eur(500);
$fiveEuro = $tenEuro->divide(2);
$tenEuro = Money::eur(1000);
$shares = $tenEuro->allocate([1,1,1]);
print($shares[0]->getAmount()); //334
print($shares[1]->getAmount()); //333
print($shares[2]->getAmount()); //333
$tenEuro = Money::eur(1000);
$oneEuro = Money::eur(100);
$oneDollar = Money::usd(100);
$oneEuro->equals($tenEuro); // false
$oneEuro->equals($oneDollar); // false
$tenEuro = Money::eur(1000);
$oneEuro = Money::eur(100);
$tenEuro->greaterThan($oneEuro); // true
$oneEuro = Money::eur(100);
$oneEuro->greaterThanOrEqual($oneEuro); // true
$tenEuro = Money::eur(1000);
$oneEuro = Money::eur(100);
$oneEuro->lessThan($tenEuro); // true
$oneEuro = Money::eur(100);
$oneEuro->lessThanOrEqual($oneEuro); // true
$oneEuro = Money::eur(100);
print($oneEuro->format()); // 1,00 €