Category Archives: Number

Number.toFixed()

Actionscript:
  1. var someValue:Number = 2.0480531167374427;
  2.  
  3. // want to show only 3 decimal places?
  4. trace(someValue.toFixed(3)); // outputs 2.048

An easy way to get rid of extra decimal values. This is useful when you want to show decimal values in text fields. I only recently noticed this in the docs, I used to do this type of thing:

Actionscript:
  1. trace(int(someValue * 1000) / 1000);  // outputs 2.048

Posted in Number | Tagged , | 4 Comments