toPrecision < Number < JavaScript
The toPrecision() method of a Number value returns a string representing the number to the specified precision.
const number = 5.123456;
console.log(number.toPrecision(5)); // "5.1235"
console.log(number.toPrecision(2)); // "5.1"
console.log(number.toPrecision(1)); // "5"
const fraction = 0.0123;
console.log(fraction.toPrecision(5)); // "0.012300"
console.log(fraction.toPrecision(2)); // "0.012"
console.log(fraction.toPrecision(1)); // "0.01"