abivia/money
最新稳定版本:1.2.0
Composer 安装命令:
composer require abivia/money
包简介
Library for working with monetary values, a BCMath library with rounding support.
README 文档
README
Abivia Money is a compact, fluent library that implements correct rounding logic, with the option to fall back to BCMath's truncation mode. Money instances are immutable.
Money implements the BCMath functions essential for financial calculations, along with other useful
functions ceil, floor, max, min, and round.
Money objects can retain individual scale values. If an operation is performed on two objects with different scale values, the result will retain the higher precision.
The Rounding Problem
Example: $35.04 / 1.15 = $30.469565217
When working with currencies there are no fractional cents. This should be rounded to 30.47. But
echo bcdiv('35.04', '1.15', 2); 30.46
That's a rounding error of .95 cents instead of 0.05 cents. Not a big deal for a dozen calculations but made a million times, that's a difference of $900,000.
use Abivia\Money; Money::setScale(2); echo Money::make('35.04')->div('1.15'); 30.47
统计信息
- 总下载量: 664
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-24