Ant*_*ton 7 javascript algorithm floating-point binary sum
下一个代码的结果是什么:
if(0.3 == ( 0.1 + 0.1 + 0.1 ))
{
alert(true);
}
else
{
alert(false);
}
Run Code Online (Sandbox Code Playgroud)
这很奇怪,但结果将是错误的.
原因是结果
0.1 + 0.1 + 0.1
将会
0.30000000000000004
怎么能解释这种行为?