This is a bug. Can you please file it? Apparently when the AS3 compiler compiles
trace(i - 952.86), it doesn't convert the 952.86 to the exact same Number that
the player does when it executes parseFloat() on "952.86". They
should produce identical Numbers, and the different should be exactly 0. You should be aware, however, that the
Number they produce will be very close but not exactly equal to decimal 952.86.
The reason is that Number stores values as binary fractions, not decimal
fractions. A decimal fraction like 0.375 has a terminating binary
representation (0.011 =0 x 1/2 + 1 x 1/4 + 1 x 1/8) but a decimal fraction like
952.86 has a non-terminating binary representation that would require an
infinite number of bits to represent exactly. This is why an _expression_ like 0.1
+ 0.2 == 0.3 evaluates to false! This is NOT a bug, it's a consequence that
microprocessors and computer languages tend to do floating-point arithmetic in
binary, not in decimal. The Number type in AS3 is the same as the 'double' type
in Java and C++, which have the same issue. - Gordon From: Anyone has any idea why it's not possible to convert a string to a
number without losing precision? var s:String = "952.86"; - boon Yahoo! Mail |
- RE: [flexcoders] In actionscript, converting from string to n... Gordon Smith