我正在尝试接收一个带有小数字(最多8个小数)的数学运算的结果,我收到了一个浮点型结果,但格式使其他数字保持错误:
$a = round($x, 8); //returns 0.0478674, that's correct
$b = round($y,8); //returns 0.04786261, that's correct
$z = $a - $b; //z returns 4.7899999999976E-6, and not 0.00000479 as I was expecting我也试过了
$w = round($z,8); //but w returns 4.79E-6, and not 0.00000479 as I was expecting我的问题是因为数字4.7899999999976E-6在其他计算中给出了一个错误,并且它是一个丑陋的数字,无法显示给用户。
如何将此号码设为0.00000479?
发布于 2020-03-11 10:15:21
您可以使用number_format
$w = number_format($z,8);发布于 2020-03-11 10:17:43
在帮助中,number_format应该按照您的要求进行操作:https://www.php.net/manual/en/function.number-format.php
针对您在此处的特定需求:
$w = number_format($z,8);https://stackoverflow.com/questions/60628303
复制相似问题