Hey Everyone How do you round a number to 2 decimal places using the Math.round function? Thanks in advance. -turner2000
Math.round(number*100)/100
this works OK but if the number is say 12.40 the result will be 12.4. I have tried using "int" instead of round and it strangely takes 12.40 and displays 12.39 ?????
cant you check for the decimal?..and if NOT present..add it to the end? something like this: (or alternative) actionscript Code: var targetNumber:Number = 27.40;var tempNum = Math.round(targetNumber*100)/100;var stringNum:String = String(tempNum);if(stringNum.charAt(stringNum.length-2) != "0"){ stringNum += "0"; trace("NEW NUMBER: "+stringNum)}
var targetNumber:Number = 27.40;var tempNum = Math.round(targetNumber*100)/100;var stringNum:String = String(tempNum);if(stringNum.charAt(stringNum.length-2) != "0"){ stringNum += "0"; trace("NEW NUMBER: "+stringNum)}
Last edited by whispers; 01-31-2011 at 01:53 PM.
preloader 1 2 3 4 | pop-up help | play-by-variable | dynamic anchors | slow motion | asfunction | text scroller 1 2 | pause | embed dynamic images | yahoo! maps 1 2 | paypal 1 2 | resize broswer | attachClip 1 2 | embedVar > flash | urlVar > flash 1 2 3 varObject | textFile-by-date | fake expire | save-2-text | reverse 1 2 | sharedObject 2 | xml 101 | resetBrowserSB | fullScreen z-index | resize flash 1 2 | deepLink | clipLoader | toggle | ip | setTimeout
Forum Rules