Rounds a number to a fixed number of decimal places.
When digits <= 0, rounds to the nearest integer. The base parameter defaults to 10; most callers should leave it unchanged.
digits <= 0
base
10
Number to round.
Fractional digits to keep; values <= 0 delegate to Math.round.
<= 0
Math.round
Radix used for scaling (default 10); most callers should leave this unchanged.
value rounded to digits decimal places at the given base.
value
digits
roundToPrecision(3.14159, 2); // 3.14roundToPrecision(3.005, 2); // 3.01roundToPrecision(3.7, 0); // 4 Copy
roundToPrecision(3.14159, 2); // 3.14roundToPrecision(3.005, 2); // 3.01roundToPrecision(3.7, 0); // 4
Rounds a number to a fixed number of decimal places.
When
digits <= 0, rounds to the nearest integer. Thebaseparameter defaults to10; most callers should leave it unchanged.