A PHP library for immutable money and currency handling with exact arithmetic and explicit rounding control.
Brick\Money is a PHP library for handling monetary values with exact arithmetic, avoiding floating-point rounding errors. It provides immutable classes to represent money and currencies, ensuring precise calculations and giving developers explicit control over rounding behavior. The library is designed for production-grade financial applications where accuracy is critical.
PHP developers building financial applications, e-commerce systems, or any software requiring precise monetary calculations, such as payment processors, accounting software, or budgeting tools. It is particularly suited for projects where rounding errors could lead to financial discrepancies.
Developers choose Brick\Money for its emphasis on immutability, precision, and explicit rounding control, which prevents silent financial calculation errors. Its unique selling points include support for advanced features like RationalMoney for fraction-based intermediate calculations, flexible currency conversion with exchange rate providers, and money allocation/splitting with various modes.
A money and currency library for PHP
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Based on brick/math, it avoids floating-point errors by performing exact calculations on monies of any size, crucial for financial accuracy.
Supports contexts like CashContext for cash rounding and AutoContext for auto-scaling, allowing tailored handling for different use cases.
Provides multiple allocation and splitting modes (e.g., FloorToFirst, Separate) for precise money distribution, useful in profit sharing or expense splitting.
Money instances are immutable, preventing accidental modifications and ensuring safe concurrency in applications.
Without GMP or BCMath extensions, calculations can be slower, potentially impacting high-throughput systems as noted in the requirements.
Being in 0.x versions, new release cycles introduce breaking changes, requiring careful version locking and upgrade planning.
Formatting uses NumberFormatter which converts to float, causing potential inaccuracies with very large monetary amounts, as admitted in the README.
Brick Money is an open-source alternative to the following products: