Arbitrary precision arithmetic-based Money value object. Drop-in replacement for Mathias Verraes' Money library (some use statement tweaking required). Follows GAAP suggestion to use 4 decimal places with rounding on 5th to minimize statistical influence of rounding errors.
Follows PSR-2 guidelines.
Project name is inspired by Kanye West's verse:
La la la la... wait till I get my money right!
As we all know money really should be right (and therefore not stored in floats!).
PHP 5.4.0+ BCMath Arbitrary Precision Arithmetic PHP extension
Via Composer
$ composer require keios/moneyright
$tenEuroNetPrice = Keios\MoneyRight\Money::EUR('10'); // Money::EUR(10000) integers as cents | Money::EUR(10.0) floats as literal amount
var_dump($tenEuroNetPrice->getAmount()); // int(1000) - cents
var_dump($tenEuroNetPrice->getAmountString()); // string(7) "10.0000" - literal amount in string with 4 decimal points precision
$vatTax = $tenEuroNetPrice->multiply('0.23'); // 23% VAT tax
var_dump(assert(!$vatTax->equals($tenEuroNetPrice))); // bool(true)
var_dump($vatTax->getAmountString()); // string(6) "2.3000"
$grossPrice = $tenEuroNetPrice->add($vatTax); // instances are immutable, so every operation returns new instance
var_dump($grossPrice->getAmountString()); // string(7) "12.3000"
var_dump($grossPrice->getAmount()); // int(1230) - cents
$ phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.