Using Number.toPrecision() in javascript
by Sanju[ Edit ] 2009-12-14 21:06:05
Number.toPrecision()
To
toPrecision() now:
var anumber = 123.45
anumber.toPrecision(6) //returns 123.450 (padding)
anumber.toPrecision(4) //returns 123.5 (round up)
anumber.toPrecision(2) //returns 1.2e+2 (you figure it out!)
toPrecision() is useful if your number must be of a certain length.