Using Number.toPrecision() in javascript

by Sanju 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.

Tagged in:

1082
like
0
dislike
0
mail
flag

You must LOGIN to add comments