Search This Blog

Tuesday, 2 August 2016

How to display the exponential notation of a specified number using javascript?

Html page:

<button onclick="myFunction()">Try it</button>
<p id="P1"></p>

Javascript page:

<script>
    function myFunction() {
        var num = 5.56789;
        var n = num.toExponential();
        document.getElementById("demo").innerHTML = n;
    }
</script>

Output:

5.56789e+0

No comments:

Post a Comment