【发布时间】:2018-04-16 10:36:39
【问题描述】:
我想使用 bcmath 进行非常小的数字的精确运算,但它失败了。我正在尝试计算加密货币价格,并认为 bcmath 比将浮点数转换为整数更好
这项工作:
php > echo number_format(0.000005 * 0.0025, 10);
0.0000000125
这不起作用:
php > echo number_format(bcmul(0.000005, 0.0025, 10), 10);
0.0000000000
php > echo number_format(bcadd(0.000005, 0.00000025, 10), 10);
0.0000000000
bcmath 是否有一些配置或者这是正常行为?
【问题讨论】:
-
如here 中所说,用字符串包裹数字会有所帮助