Floor function to get just lower integer of a number

We can use math function floor to get the floor of a number or the largest integer which is equal to or lower than the given number.

So by using floor we can get the floor value of an number.

Here is the syntax.
Math.floor(number)
Let us try with some examples. Floor ceil Math functions

document.write (Math.floor(11.257)); // output 11
document.write ("<br>----<br>");

document.write (Math.floor(1.56)); // output 1
document.write ("<br>----<br>");


document.write (Math.floor(-3.564)); // output -4
document.write ("<br>----<br>");


document.write (Math.floor(-7.164)); // output -8
document.write ("<br>----<br>");

Not numeric or blank inputs

We will get output as NaN for all blank and non-numeric inputs.
document.write(Math.floor()); // Output NaN 
document.write("<br>");
document.write(Math.floor('abc')); // Output NaN 
document.write("<br>");

Difference between floor() and round()

Math.floor() always returns previous lower side integer, where Math.round can return integer value higher or lower than the input value.
Example :
<script>
document.write(Math.round(5.42)+'<br>'); // Output 5
document.write(Math.floor(5.42)+'<br>'); // Output 5

document.write(Math.round(5.67)+'<br>'); // Output 6
document.write(Math.floor(5.67)+'<br>'); // Output 5

document.write(Math.round(-5.42)+'<br>'); // Output -5
document.write(Math.floor(-5.42)+'<br>'); // Output -6

document.write(Math.round(-5.67)+'<br>'); // Output -6
document.write(Math.floor(-5.67)+'<br>'); // Output -6
</script>
We can develop a script to get the floor value of a number

Demo of floor function

You can read the php math floor function


plus2net.com




Makwana Parvez

11-02-2019

very good and explaination of example is very nice

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer