Search This Blog

Tuesday, 2 August 2016

How display the formatted number in javascript?

Html page:

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

Javascript page:

<script>
    function myFunction() {
        var num = 13.3714;
        document.getElementById("demo").innerHTML = num.toPrecision(2);
    }
</script>

Output:

13

No comments:

Post a Comment