PHP implementation of Fowler's Money pattern

1.3.0-beta1 2014-08-24 17:01 UTC


Build Status

PHP 5.4+ 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.


use Money\Money;

$fiveEur = Money::Euro(500);
$tenEur = $fiveEur->add($fiveEur);

list($part1, $part2, $part3) = $tenEur->allocate(array(1, 1, 1));

// Format
// $1,234.56
echo Money::USD(123456)->format();

The documentation is available at

Money Format

When creating a money object, it is expected to be in the lowest value of the currency (e.g. cents). For example, $1,234.56 is actually 123,456 cents.

For conversion from cents to dollars:

$dollars = $cents * 100;

For conversion from dollars to cents:

$cents = $dollars / 100;


Install the library using composer. Add the following to your composer.json:

    "require": {
      "srtfisher/money": "dev-master"
    "minimum-stability": "dev"

Now run the install command.

$ composer.phar install


See MoneyBundle or TbbcMoneyBundle for Symfony integration.