Number.toPrecision() (Method)

Convert a number to a string automatically selecting fixed or exponential notation.


ECMAScript edition - 3
JavaScript - 1.5
JScript - 5.5
Internet Explorer - 5.5
Netscape - 6.0
Property/method value type:String primitive
JavaScript syntax:-myNumber.toPrecision(aNumber)
Argument list:aNumberThe number of digits after the decimal point

This method will convert a number to a string and will select either a fixed or exponential notation according to the magnitude of the value being converted.

This would be useful where you have an arbitrary collection of values and don't want them presented in a ragged looking column.

See also:Number.toExponential(), Number.toFixed()


ECMA 262 edition 3 - section -