keios / moneyright
Precise, GAAP-compliant, database-friendly Money Value Object
Installs: 53 947
Dependents: 1
Suggesters: 0
Security: 0
Stars: 20
Watchers: 4
Forks: 4
Open Issues: 1
Requires
- php: >=5.4.0
- ext-bcmath: *
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-11-09 17:40:26 UTC
README
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!).
Requirements
PHP 5.4.0+ BCMath Arbitrary Precision Arithmetic PHP extension
Install
Via Composer
$ composer require keios/moneyright
Usage
$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
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.