我正在尝试像这样添加数字
$ctr = 0.0000001 + 0.0000001+ 0.0000001+ 0.0000001+ 0.0000001+ 0.0000001;
echo floatval($ctr);
它给出这样的结果 2.0E-5
我已经尝试过,number_format,round 等...但结果是一样的,它应该是 0.0000006
请帮助我实现这一目标。
最佳答案
我想你可以试试BCMath正如它所宣传的那样:
For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings
示例代码:
$sum = bcadd('0.0000001','0.0000001',7); // 7 = num of digits after decimal point
echo $sum; // 0.0000002
关于php - 在 PHP 中大量添加带小数点的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19678128/