失去意义php round


Loss of significance php round

我有以下代码

$suma += round(1*43067.8000,2);
$suma += round(-1*18875.1800,2);
$suma += round(-1*15293.9700,2);
$suma += round(-1*8898.6500,2);
print $suma;

输出为3.6379788070917E-12

如果在加法之前将数字四舍五入,为什么答案不是0 ?

Round仍然返回浮点数。因为它是浮点数,所以可能总是有很小的误差。在这种情况下,这会导致你的答案不等于0。