货币php,Money:一个Fowler货币模式的PHP实现

Money

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d6f6e65797068702f6d6f6e65792e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6f6e65797068702f6d6f6e65792e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d6f6e65797068702f6d6f6e65792e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d6f6e65797068702f6d6f6e65792e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f6e65797068702f6d6f6e65792e7376673f7374796c653d666c61742d737175617265

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f656d61696c2d7465616d406d6f6e65797068702e6f72672d626c75652e7376673f7374796c653d666c61742d737175617265

e672b3637710322f077b61c970ed77e4.png

PHP 5.5+ library to make working with money safer, easier, and fun!

"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin

In short: You shouldn't represent monetary values by a float. Wherever you need to represent money, use this Money value object. Since version 3.0 this library uses strings internally in order to support unlimited integers.

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)));

The documentation is available at http://moneyphp.org

Install

Via Composer

$ composer require moneyphp/money

Features

JSON Serialization

Big integer support utilizing different, transparent calculation logic upon availability (bcmath, gmp, plain php)

Money formatting (including intl formatter)

Currency repositories (ISO currencies included)

Money exchange (including Swap implementation)

Documentation

Testing

We try to follow BDD and TDD, as such we use both phpspec and phpunit to test this library.

$ composer test

Contributing

We would love to see you helping us to make this library better and better. Please keep in mind we do not use suffixes and prefixes in class names, so not CurrenciesInterface, but Currencies. Other than that, Style CI will help you using the same code style as we are using. Please provide tests when creating a PR and clear descriptions of bugs when filing issues.

Security

If you discover any security related issues, please contact us at team@moneyphp.org.

License

The MIT License (MIT). Please see License File for more information.

Acknowledgements

This library is heavily inspired by Martin Fowler's Money pattern. A special remark goes to Mathias Verraes, without his contributions, in code and via his blog, this library would not be where it stands now.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值