Javascript Number toExponential()

Introduction

The Javascript Number toExponential() method formats the Number object in exponential notation.

numObj.toExponential([fractionDigits])
Parameter Optional Meaning
fractionDigits Optional An integer specifying the number of digits after the decimal point.

fractionDigits defaults to as many digits as necessary to specify the number.

Using toExponential()

var numObj = 9876.1234;

console.log(numObj.toExponential());/*from w  ww .  jav a  2  s . c om*/
console.log(numObj.toExponential(4));
console.log(numObj.toExponential(2));
console.log(9876.1234.toExponential());

The toExponential() method returns a string with the number formatted in exponential notation (aka e-notation).

The toExponential() accepts one argument, which is the number of decimal places to output.

let num = 10; 
console.log(num.toExponential(1));  // "1.0e+1" 



PreviousNext

Related