Convert a number, without keeping any decimals: - Javascript Number

Javascript examples for Number:toFixed

Description

Convert a number, without keeping any decimals:

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 w w w .  j av a2 s . c o m
    var num = 5.56789;
    var n = num.toFixed()
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials