Yes, you've discovered the joys of floating point maths. Not a bug,
just a fact of life for anyone working in just about every programming
language there is.
Work in integers if you want integer results, or use the functions
under the Math class to round things to suit your needs.
Guy
On 26/11/2009, at 7:33 AM, kidl33t wrote:
I have encountered an odd bug. In the process of creating a little
numeric stepper component (a text box with an up/down stepper beside
it) I have found an odd rounding error. Starting from 0.0 and adding
0.1 increments, I get the follow console output.
currentNumber: 0 increment: 0.1
result: 0.1
currentNumber: 0.1 increment: 0.1
result: 0.2
currentNumber: 0.2 increment: 0.1
result: 0.30000000000000004
As you can see, .2 + .1 is yielding 0.30000000000000004. This
behaviour happens at at many numbers actually.
You can verify this yourself by simply doing a: trace( (0.1 + 0.2) );
The other flex developer at our company can also see this error, so
I don't think it's isolated to my box or particular build. Does
anyone know anything about this?