1. Go to this page and download the library: Download macmotp/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/ */
macmotp / money example snippets
php
use Macmotp\Money;
use Macmotp\Support\CurrencyCode;
$money = new Money(12345, CurrencyCode::USD);
// Default format based on each currency
echo $money->print();
// (string) '123.45$'
// Override the default
echo $money->withCode()
->withSpace()
->withoutDecimals()
->print();
// (string) '123 USD'
php
use Macmotp\Money;
use Macmotp\Support\CurrencyCode;
$moneyOne = new Money(200, CurrencyCode::USD);
$moneyTwo = new Money(300, CurrencyCode::USD);
echo $moneyOne->add($moneyTwo);
// new Money(500, CurrencyCode::USD)
php
use Macmotp\Money;
use Macmotp\Support\CurrencyCode;
$moneyOne = new Money(200, CurrencyCode::USD);
$moneyTwo = new Money(300, CurrencyCode::USD);
$moneyThree = new Money(400, CurrencyCode::USD);
echo Money::max($moneyOne, $moneyTwo, $moneyThree);
// new Money(400, CurrencyCode::USD)
echo Money::avg($moneyOne, $moneyTwo, $moneyThree);
// new Money(300, CurrencyCode::USD)
php
use Macmotp\Money;
use Macmotp\Support\CurrencyCode;
$moneyOne = new Money(200, CurrencyCode::USD);
$moneyTwo = new Money(300, CurrencyCode::USD);
echo $moneyOne->isLessThan($moneyTwo);
// (bool) true
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.