keios / moneyright
精确、符合GAAP、数据库友好的货币值对象
v1.0.9
2023-11-01 12:19 UTC
Requires
- php: >=5.4.0
- ext-bcmath: *
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-28 17:12:33 UTC
README
基于任意精度算术的货币值对象。可替换Mathias Verraes的Money库(可能需要调整一些使用语句)。遵循GAAP的建议,使用4位小数,并在第5位进行四舍五入,以最小化舍入误差的统计影响。
遵循PSR-2指南。
项目名称灵感来源于Kanye West的歌词。
La la la la... wait till I get my money right!
众所周知,金钱确实应该是正确的(因此不应存储为浮点数!)。
需求
PHP 5.4.0+ BCMath任意精度算术PHP扩展
安装
通过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
贡献
有关详细信息,请参阅CONTRIBUTING。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。