Javascript examples for Math:floor
The floor() method rounds a number down to the nearest integer, and returns the result.
Parameter | Description |
---|---|
x | Required. The number you want to round |
A Number, representing the nearest integer when rounding downwards
The following code shows how to Round a number downward to its nearest integer:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww .jav a2 s.c om*/ var a = Math.floor(0.60); var b = Math.floor(1.40); var c = Math.floor(5); var d = Math.floor(5.1); var e = Math.floor(-15.1); var f = Math.floor(-51.9); var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f; document.getElementById("demo").innerHTML = x; } </script> </body> </html>