BigDecimal.prototype.toPrecision

Returns a string representation of the BigDecimal rounded to the specified number of digits.

Syntax

toPrecision(digits, roundingMode)

Parameters

Return value

A string representing the value. Can be in exponential notation.

Examples

123.4567m.toPrecision(1)
"1e+2"
123.4567m.toPrecision(4)
"123.5"
123.4567m.toPrecision(4, "down")
"123.4"