我有下面的语句问题
跟踪(10.12 + 13.75) //输出23.869999999999997
trace(10.12+13.75) //output 23.869999999999997
任何人都可以解释我为什么会这样,以及如何得到确切的23.87摆脱这种?
Can anybody explain me why is this so and how to get exact 23.87 out of this?
感谢
这是因为的IEEE格式的precision。
That happens because of the precision of IEEE format.
最简单的办法是使用toFixed
Simplest would be to use toFixed.
var num:Number = 10.12+13.75;
var numStr:String = num.toFixed(2);
var num2:Number = new Number(numStr);