Convert a number which has fewer decimal places than requested: - Javascript Number

Javascript examples for Number:toFixed

Description

Convert a number which has fewer decimal places than requested:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the fixed number.</p>

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

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

<script>
function myFunction() {//from   w ww .j  a v a2 s.c  om
    var num = 5.56789;
    var n = num.toFixed(10)
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials