Math Floor function of Javascript returns the nearest smaller value to the specified number. Math floor function means the floor value i.e. lower value for the specified value. Math.floor(x) function returns the lower nearest value for the specified number. Math.floor function truncates the decimal precision point values of the number and returns the smallest integer. If the specified number is an integer value then Javascript Math floor function returns the same value.
Syntax for Javascript Math Floor Function
Math.floor(x);
Math.floor function accepts value as number as returns nearest lower integer value for it.
Examples of Javascript Math Floor Function
document.write(Math.floor(0.51) + "<br />"); document.write(Math.floor(2) + "<br />"); document.write(Math.floor(2.1) + "<br />"); document.write(Math.floor(2.84) + "<br />"); document.write(Math.floor(-2.44) + "<br />"); document.write(Math.floor(-6.44) + "<br />"); document.write(Math.floor(-6.94) + "<br />"); // Output: // 0 // 2 // 2 // 2 // -3 // -7 // -7
Continue to next tutorial: Javascript Math Pow Function to learn how to calculate the value of base according to its exponential power.