How to use toExponential() Method In Javascript
JavaScript Number toExponential() method is used to convert a number to its exponential form. It returns a string representing the Number object in exponential notation. The toExponential() method is used with a number as shown in the above syntax using the ‘.’ operator. This method will convert a number to its exponential form.
Syntax:
number.toExponential(value)
Example: toExponential(2)
represents the number 12345.6789
in exponential notation with 2 digits of precision. The output might look like 1.23e+4
, where 1.23
is the significand and 4
is the exponent.
Javascript
const myNumber = 12345.6789; // Using toExponential with precision const exponentialNotation = myNumber.toExponential(2); console.log(exponentialNotation); |
1.23e+4
Floating point number precision in JavaScript
The representation of floating points in JavaScript follows the IEEE-754 format. It is a double-precision format where 64 bits are allocated for every floating point.
The displaying of these floating values could be handled using these methods:
Table of Content
- Using toFixed() Method
- Using toPrecision() Method
- Using toExponential() Method