# Flash counting bug?

This is part of a bigger project, but I've tried to simplify the problem.

My basic logic is:

Action 1: If the decimal point is 0.0 then add 0.2 to it.
Action 2: If the decimal point is 0.8 then add 0.2 to it.
Action 3: If the decimal point is 0.6 then add 0.2 to it.
Action 4: If the decimal point is 0.4 then add 0.2 to it.
Action 5: If the decimal point is 0.2 then add 0.2 to it.
Action 6: Go back to action 1

In theory, this should continually add 0.2 to the variable lapZ forever BUT it doesn't!

If you start at 0, it fails to add any more after 0.6! If you start at 1.8 if fails to add more after 2.4

Below is a simplified version of the script I'm using to calculate the decimal point and the loop of if/then statements:

decimalP = _root.lapZ-Math.floor(_root.lapZ);
decimalP == 0 ? _root.lapZ += 0.2 : null;
decimalP == 0.8 ? _root.lapZ += 0.2 : null;
decimalP == 0.6 ? _root.lapZ += 0.2 : null;
decimalP == 0.4 ? _root.lapZ += 0.2 : null;
decimalP == 0.2 ? _root.lapZ += 0.2 : null;

I found this making a small flash game a year ago while detecting how far around a track the car had travelled (5 hit tests) and having just purchased Studio 8, the bug still appears to be there.

Any ideas? Is my logic wrong, or is it a bug?
• ###### 1. Re: Flash counting bug?
binary computers do not store exact decimal numbers. what you think is 0.2 might be 0.2000000000000001 in your computer. when you test if this number is exactly 0.2 the result is false.