AS3 Round Decimal Places


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var myNumber:Number = 123.4597890;
  2. trace(roundDecimals(myNumber, 2));
  3.  
  4. function roundDecimals(num:Number, numDecimalPlaces:int):Number {
  5. return Math.round(num * Math.pow(10, numDecimalPlaces) ) / Math.pow(10, numDecimalPlaces);
  6. }
  7.  
  8. // OUTPUT
  9. // 123.46

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.