PHP的减法给出错误的答案

时间:2019-05-15 11:35:55

标签: php subtraction

执行以下操作时得到错误的结果

$n1 = 178.200;
$n2 = 89.100;
$n3 = 178.199;
$n4 = 89.101;
$n5 = 170.999;
$grandTotal = $n1+$n2+$n3+$n4+$n5;
$discount = 700.000;
$netTotal = $grandTotal - $discount;
echo "Grand Total:".$grandTotal."<br>";
echo "Discount:".$discount."<br>";
echo "Net Total:".$netTotal."<br>";

输出:

Grand Total: 705.599
Discount: 700.000
Net Total: 5.5989999999999

但是705.599-700.000 = 5.599对吗?

为什么我要得到这个5.5989999999999?

0 个答案:

没有答案