Decimal value object for PHP.
When working with monetary values, normal data types like int or float are not suitable for exact arithmetic. Handling them as string is a workaround, but as value object you can more easily encapsulate some of the logic.
Solutions like https://php-decimal.io require a PHP extension. This makes it faster, but also more difficult for some servers to be available.
- Basic math operations supported
- Immutability
Note: This library is a sandbox/showcase and for testing right now only. Use with Caution.
bcmath
PHP extension enabled
composer require spryker/decimal:dev-master
See Documentation for more details.
- Rounding
- ceil()/floor()
- toInt()
- Edge case values (very small values)
- sum(), average(), max(), min() as static methods?
- modulo()?
- shift()?
- isEven()/isOdd()?