可能重复:
限制浮点精度问题的实践
当我将新的 totalSubs 列表添加到运行总计时,PHP 返回一个奇怪的值。我生成了以下输出(见第 40 行):
1 The total currently '0' (integer) + new TotalSub '-26969.55' type(double) = total '-26969.55'
2 The total currently '-26969.55' (double) + new TotalSub '249.6' type(double) = total '-26730.05'
...
39 The total currently '-164.89' (double) + new TotalSub '61.95' type(double) = total '-112.94'
40 The total currently '-102.94' (double) + new TotalSub '98.71' type(double) = total '-5.3300000000009'
41 The total currently '-5.3300000000009' (double) + new TotalSub '50' type(double) = total '45.769999999999'
PHP生成是:
echo ($count++) . " The total currently '$totalTrans' (".gettype($totalTrans).") + new TotalSub '$totalVar' type(".gettype($totalVar).") = total '" . ($totalTrans + $totalVar) ."'<br />";
如何修复 00000000009?