azathoth / money
Fowler的Money模式的PHP实现
1.2.2
2014-11-16 20:13 UTC
Requires
- php: >=5.3.3
- azathoth/money-math: dev-master
- kdyby/doctrine: 2.1.*
- nette/utils: 2.2.*
Requires (Dev)
- phpunit/phpunit: 4.*
Suggests
- Sylius/SyliusMoneyBundle: Sylius' Symfony2 integration with Money library
- TheBigBrainsCompany/TbbcMoneyBundle: Very complete Symfony2 bundle with support for Twig, Doctrine, Forms, ...
- pink-tie/money-bundle: Pink-Tie's Symfony2 integration with Money library
This package is not auto-updated.
Last update: 2024-09-10 08:20:58 UTC
README
PHP 5.3+ 库,使金钱操作更安全、更简单、更有趣!
"如果每次我看到有人用FLOAT来存储货币,我就能得到99.9997634美元" -- Bill Karwin
简而言之:你不应该用浮点数来表示货币值。无论何时需要表示货币,请使用这个Money值对象。
<?php use Money\Money; $fiveEur = Money::EUR(500); $tenEur = $fiveEur->add($fiveEur); list($part1, $part2, $part3) = $tenEur->allocate(array(1, 1, 1)); assert($part1->equals(Money::EUR(334))); assert($part2->equals(Money::EUR(333))); assert($part3->equals(Money::EUR(333)));
文档可在 http://money.readthedocs.org 查阅
安装
使用 composer 安装库。在您的 composer.json
中添加以下内容:
{ "require": { "mathiasverraes/money": "dev-master" }, "minimum-stability": "dev" }
现在运行 install
命令。
$ composer.phar install
集成
有关 MoneyBundle
或 TbbcMoneyBundle
的信息,请参阅 Symfony集成。