Math.round()

Math.round() rounds a number to the nearest integer:

   Math.round(4.7);  // returns 5
   Math.round(4.4);  // returns 4

HTML file: Displayed by browser:
<body>
<p>Math.round() rounds a number to its nearest integer:<p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("demo").innerHTML =
    Math.round(4.3);
}
</script>
</body>

Math.round() rounds a number to its nearest integer:


BackTable of ContentsNext