PDA

View Full Version : How To Make Flash Round?


raviel
06-16-2010, 03:37 AM
I have a button that adds .01 to a total, but when it gets to around 6 it ends up being something like this .0600000000005 how can I fix this? This is what my code looks like so far...

var clicks:Number=0;
button.addEventListener(MouseEvent.CLICK,addTime);
function addTime (e:MouseEvent):void
{
total_time +=30;
clicking.text=String(clicks +=0.01);
}

Pinto
06-16-2010, 12:50 PM
Math.round() will round a number to the nearest integer. It's more of a workaround, you could store the clicks as an integer and just divide it by 100 when you convert it to a string for clicking.text

neilmmm
06-16-2010, 01:32 PM
google flash and floating point ... flash can have problems with decimals