JS: Number.prototype.toExponential

By Xah Lee. Date: . Last updated: .
number.toExponential(fractionDigits)

Return a string representation of number in exponential notation (e.g. "3.12e+2"), with fractionDigits fraction digits.

If fractionDigits is undefined, include as many significand digits as necessary to uniquely specify the number.

console.log((3.12345).toExponential(1) === "3.1e+0");
console.log((3.12345).toExponential(2) === "3.12e+0");
console.log((3.12345).toExponential(3) === "3.123e+0");

console.log((12.345).toExponential(1) === "1.2e+1");
console.log((12.345).toExponential(2) === "1.23e+1");
console.log((12.345).toExponential(3) === "1.235e+1");

console.log((0.123).toExponential(1) === "1.2e-1");
console.log((0.123).toExponential(2) === "1.23e-1");
console.log((0.123).toExponential(3) === "1.230e-1");