money 0,1,5 editorconfig styleci travis-ci Packagist phpunit

PHP implementation of Fowler's Money pattern.

Money

Latest Version Build Status Code Coverage Quality Score Total Downloads

Email

Money PHP

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.

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

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

Please see the official 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 [email protected].

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.

Related Repositories

money

money

A Ruby Library for dealing with money and currency conversion. ...

money

money

PHP implementation of Fowler's Money pattern. ...

money.js

money.js

money.js is a tiny (1kb) javascript currency conversion library, for web & nodeJS ...

money-rails

money-rails

Integration of RubyMoney - Money with Rails ...

Money

Money

Swift value types for working with money & currency ...


Top Contributors

sagikazarmark mathiasverraes frederikbosch texdc marijn jongotlin thewilkybarkid umpirsky piotrantosik pamil camspiers bendavies afoeder alexgt9 asm89 elstamey IsabelleJaffrezic h4cc lucasmichot philippe-levan rgeraads RobinMalfait Sharom sahildua2305

Dependencies

package version
php >=5.5
dev phpunit/phpunit ^4.5
ext-bcmath *
ext-gmp *
ext-intl *
florianv/swap ^3.0
psr/cache ^1.0
cache/taggable-cache ^0.4.0
phpspec/phpspec ^2.5
henrikbjorn/phpspec-code-coverage ^2.0.2
moneyphp/iso-currencies ^3.0
sllh/php-cs-fixer-styleci-bridge ^2.1
php-http/message ^1.4
php-http/mock-client ^0.3.3

Releases

-   v3.0.0-beta.2 zip tar
-   v3.0.0-beta zip tar
-   v3.0.0-alpha zip tar
-   v1.3.0 zip tar
-   1.2.1 zip tar
-   1.2.0 zip tar
-   1.1.0 zip tar
-   1.0.0 zip tar