Recently I was asked if I know how to show a number with a fixed number of digits after the decimal point. Here is how it can be done:

var num:Number = 12.3456;
trace(num.toFixed(2));// => 12.34

ATTENTION: This method toFixed returns String. If you want to have a Number after using this method you should use casting or:

var num:Number = 12.3456;
var num2:Number = Number(num.toFixed(2));
// => returns Number not String
Share
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

*


TxEff - The Flash Text Effects