Search This Blog

Tuesday, 2 August 2016

How to display the fixed number in javascript?

Html page:

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

Javascript page:

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

Output:

5.57

No comments:

Post a Comment