On 12/4/05, Hans Wichman <[EMAIL PROTECTED]> wrote: > > Hi peeps, > related discussions have been on here before, but i didn't find a real > answer. > Imagine this piece of code: > var i = 0; > > onEnterFrame = function () { > i = i + 0.1; > trace (i); > if (i == 0.7) trace("here"); > } > > as you might expect, after running for 7 frames, it traces "here". > However if you change 0.7 to 0.8, it stops working. > > I assume this is to floating point math and rounding errors and stuff? > In what way can i check for equality to 0.7 then? With a bigger than, > smaller than construction? > > This seems so weird to me... >
This will check to make sure the numbers are equal to within 2 decimal places. change both 100's to set how many decimal places you want to check. if(Math.round(i*100) == (0.8 *100)) -David R _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders