Adrian Zając wrote:

>    trace (0.27 + 0.03);   // output --> 0.30000000000000004
>
> Can anyone tell me why I get this weird result in output window?


As people have said, it's a problem with decimals. It's not a problem with
Flash--it's a problem with binary numbers.

Integers are accurate because all integers are a multiple of 1, and binary
does just fine with combining 0's and 1's, the only possibile values of a
digit in the binary system.

If you think of decimals as fractions, maybe it will help you understand the
issue. In binary, a digit can only be a multiple of 2: 1/2, 1/4, 1/8/ 1/16,
1/32, and so on. You can create numbers that aren't multiples of two by
adding multiple digits. For example, 1/4 + 1/8 = 3/8, or .375.

This works pretty well, until you get numbers with a lot of decimal places.
At some point, you will find a decimal that is impossible to make using
powers of 2.

Cordially,

Kerry Thompson
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to