Number toExponential() Method - Javascript Number

Javascript examples for Number:toExponential

Description

The toExponential() method converts a number into an exponential notation.

Syntax

number.toExponential(x);

Parameter Values

Parameter Description
x Optional. An integer between 0 and 20 representing the number of digits after the decimal point.

Return Value:

A String, representing the number as an exponential notation

The following code shows how to Convert a number into an exponential notation:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   www. j av a  2  s.  c  o m*/
    var num = 52.56789321123;
    var n = num.toExponential(3);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials