trace( ">> " + (399.6-(Math.floor(399.6))) );
打印出
>> 0.6000000000000227
为什么?
浮点舍入误差。浮点数不能再present一些值完全相同,所以你看到的是使用FP数的限制。尾数(对FP民,使该精度的一部分)是只有一定的比特数,而当某物也不可能完全重新presented,则得到像上述结果。我知道一个事实,即0.1不能重新presented完全,所以它是有道理的,0.6不能为好。
Floating Point rounding errors. Floating point numbers can't represent some values exactly, so what you are seeing is the limitations of using FP numbers. The mantissa (the part of the FP num that gives the accuracy) is only a certain number of bits, and when something can't be exactly represented, you get results like the above. I know for a fact that 0.1 can't be represented exactly, so it makes sense that 0.6 can't as well.