JavaScript: Number.prototype.toExponential

By Xah Lee. Date: . Last updated: .
number.toExponential( fractionDigits )
Return a string representation of number in exponential notation, with fractionDigits fraction digits.

Example of return string: "3.12e+2". (the “e+2” means multiply by 10^2)

If fractionDigits is undefined, include as many significand digits as necessary to uniquely specify the number (just like in ToString except that in this case the number is always output in exponential notation).

let num = 3.12345;

console.log( 
 num.toExponential ( 1 ) === "3.1e+0" ); // true

console.log( 
 num.toExponential ( 2 ) === "3.12e+0" ); // true

console.log( 
 num.toExponential ( 3 ) === "3.123e+0" ); // true
let num = 12.345;

console.log( 
 num.toExponential ( 1 ) === "1.2e+1" ); // true

console.log( 
 num.toExponential ( 2 ) === "1.23e+1" ); // true

console.log( 
 num.toExponential ( 3 ) === "1.235e+1" ); // true
let num = 0.123;

console.log( 
 num.toExponential ( 1 ) === "1.2e-1" ); // true

console.log( 
 num.toExponential ( 2 ) === "1.23e-1" ); // true

console.log( 
 num.toExponential ( 3 ) === "1.230e-1" ); // true
JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Number

prototype