Money for PHP models currency amounts as value objects using string integers, formatting, and ISO currency data instead of floats.
Overview
Money is a PHP library that implements Martin Fowler’s Money pattern so applications store and compute monetary amounts without floating-point rounding errors. The documentation advises using a dedicated Money object wherever currency values appear in code.
Since major version 3, amounts are held as strings internally so arithmetic can use arbitrarily large integers. The BCMath extension is required, with optional GMP or plain PHP calculation paths depending on availability. Features include JSON serialization, money formatting with intl support, and currency repositories that include ISO currency metadata.
Optional exchange-rate features can pull in additional packages such as Swap, as noted in the docs. Version 4 targets PHP 8.0 and newer supported runtimes; older PHP versions can use prior library releases. Install through Composer.
The design is attributed in the project to Fowler’s pattern and community contributions, with tests run via PHPUnit and an optional Docker workflow for contributors.
Key features
- Money value objects instead of floats
- String-based arbitrary-precision amounts
- BCMath, GMP, or PHP arithmetic
- JSON serialization
- Intl money formatting
- ISO currency repositories
- Composer installation
Use cases
- Safe currency arithmetic in PHP apps
- Multi-currency totals without float drift
- Formatted money display
- E-commerce and billing calculations