The toExponential() Method

The toExponential() method returns a string, with a number rounded and written using exponential notation. A parameter defines the number of characters behind the decimal point:

HTML file: Displayed by browser:
<body>
<p>The toExponential() method returns a string, with the number rounded and written using exponential notation. An optional parameter defines the number of digits behind the decimal point.</p>
<p id="demo"></p>
<script>
var x = 9.656;
document.getElementById("demo").innerHTML =
    x.toExponential() + "<br />" +      // returns 9.656e+0
    x.toExponential(2) + "<br />" +    // returns 9.66e+0
    x.toExponential(4) + "<br />" +    // returns 9.6560e+0
    x.toExponential(6);                       // returns 9.656000e+0
</script>
</body>

The toExponential() method returns a string, with the number rounded and written using exponential notation. An optional parameter defines the number of digits behind the decimal point.

The parameter is optional. If you don't specify it, JavaScript will not round the number.

BackTable of ContentsNext