Return to Snippet

Revision: 41118
at February 12, 2011 06:10 by adrianparr


Initial Code
var myNumber:Number = 123.4597890;
trace(roundDecimals(myNumber, 2));

function roundDecimals(num:Number, numDecimalPlaces:int):Number {
	return Math.round(num * Math.pow(10, numDecimalPlaces) ) / Math.pow(10, numDecimalPlaces);
}

// OUTPUT
// 123.46

Initial URL

                                

Initial Description

                                

Initial Title
AS3 Round Decimal Places

Initial Tags
number, format, math

Initial Language
ActionScript 3