JS: 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 Number

  1. Format Number
  2. String to Number
  3. Number Object
  4. Number Constructor
  5. Number.prototype
Liket it? I spend 2 years writing this tutorial. Help me spread it. Tell your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Object Reference
  5. DOM Scripting
  6. SVG
  7. Blog