Rounding of a Number to X decimals


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



Copy this code and paste it in your HTML
  1. /* Returns a string representation of the number in fixed-point notation.
  2. Fixed-point notation means that the string will contain a specific number of digits after the decimal point, as specified in the fractionDigits parameter.
  3. The valid range for the fractionDigits parameter is from 0 to 20.
  4. Specifying a value outside this range throws an exception.
  5.  
  6. */
  7.  
  8. var num:Number = 4;
  9. trace(num.toFixed(2)); // 4.00
  10.  
  11. var num:Number = 7.31343;
  12. trace(num.toFixed(3)); // 7.313

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.