Math floor() Method - Javascript Math

Javascript examples for Math:floor

Description

The floor() method rounds a number down to the nearest integer, and returns the result.

Parameter Values

Parameter Description
x Required. The number you want to round

Return Value:

A Number, representing the nearest integer when rounding downwards

The following code shows how to Round a number downward to its nearest integer:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials