11.01.2011

Round a number with specified decimal places in AS3

Dear Friends,

I didn't find a Math function to round a number with specified decimal places in Action Script 3.0

Here is the function for that.


function roundDecimal(num:Number, precision:int):Number{
var decimal:Number = Math.pow(10, precision);
return Math.round(decimal* num) / decimal;
}

trace(roundDecimal(34.47464,2));

Output: 34.47

Have a great day!

Firos