Using Number.toPrecision() in javascript - Javascript Views : 362
Tagged in : Javascript
Send mail vote down 0 vote down 0
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.

By - Sanju, On - 2009-12-14




    Login to add Comments .