Number.prototype.toPrecision

Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.

Syntax

toPrecision(precision?)

Parameters

Return value

A string representation of the number.

Examples

(1234.5678).toPrecision(2)
"1.2e+3"
(1234.5678).toPrecision(6)
"1234.57"