我正试图绕过双0.0045
。当我打电话给...
echo round($theFloat, 3);
我得到0.004,而不是0.005,这是预期的反应。
以下是代码:
$increase = 1.1;
$previousPrice = round(0.11 / $increase, 2);
$nextPrice = round(0.11 * $increase, 2);
$afterCut = round(0.11 * 0.95, 6);
$willSend = $afterCut - $previousPrice;
echo round($willSend, 3);
答案 0 :(得分:1)
试试这个
$increase = 1.1;
$previousPrice = 0.11 / $increase;
$nextPrice = 0.11 * $increase;
$afterCut = round(0.11 * 0.95, 6);
$willSend = $afterCut - $previousPrice;
echo round($willSend, 3);
答案 1 :(得分:1)
虽然您拥有的内容,如0.0045,但实际的值约为0.00449999999999999966,因为IEEE 754 floating point values cannot specify exactly that number。 值在舍入到3位时为0.004。