3 Replies Latest reply on Jul 13, 2006 4:57 AM by Nixy

# Simple Math equation in Flash BUGGSSS

I'm doing a simple Minus equation
here it is:

Question : 100.24 - 100.23

Question : 10.24 - 10.23

Question : 0.24 - 0.23

Why when i'm over 10.00, Flash gives me a wrong answer. Also, there is somethings weird. If I put the number in textfields and I display the result, it will be different of the same equation in a trace.

I need to build a form that calculate money. It's a problem for me if decimal are not valid!

Any idea?
• ###### 1. Re: Simple Math equation in Flash BUGGSSS
That's a common problem when calculating with decimals, not only in Flash. There were some good explanations in this forum, but it seems I can't come up with the right search terms atm... In short, there are always some rounding operations when calculating with decimals, resulting in those strange results. You can try to search the forum, or read http://en.wikipedia.org/wiki/Floating_point, if you want to know more about it.
A way to avoid this is to convert the decimals into full numbers first, calculate, and then convert back to decimals. E.g., if you always have 2 decimal parts, multiply by 100 to get full numbers, do the calculation, then divide the result by 100 to move the decimal point back in place.

hth,
blemmo
• ###### 2. Re: Simple Math equation in Flash BUGGSSS
Forgot: when you take the numbers from a textfield, they come as a string, so you have to convert them to a number first before calculating with it. The parseFloat() function does this conversion.

cheers,
blemmo
• ###### 3. Re: Simple Math equation in Flash BUGGSSS
That works great.