Posted By

adrianparr on 02/12/11


Tagged

number format math decimal truncate round as3 shorten decimals Places pow


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

ezhis
weavermedia
hausnes


AS3 Round Decimal Places


 / Published in: ActionScript 3
 

  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  

You need to login to post a comment.