PHP 舍入意外结果

PHP Round unexpected result

我对 php 轮函数有疑问。回合功能无法正常工作:

$value = 562.92578125;

round($value,1); // return 562.9 (correctly)
round($value,2); // return 562.9299999999999 (wrong)
round($value,3); // return 562.926 (correctly)

它工作正常,

$value = 562.92578125;

round($value,1); // return 562.9
round($value,2); // return 562.93
round($value,3); // return 562.926

demo here

作为解决方法尝试使用:

number_format(round($value, 1), 1);
number_format(round($value, 2), 2);
number_format(round($value, 3), 3);

此外,请看这里:Can I rely on PHP php.ini precision workaround for floating point issue