What is Math.floor() in JavaScript?
Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains the floor() function, which is used to compute the largest integer less than or equal to a specified number.
Syntax
Math.floor(param);
Parameter
param: This is the input value of theNumbertype for which we want to find thefloor().
Numberin JavaScript is a 64-bit double-precision value that is the same asdoublein C# or Java.
Return value
Number: This rounds the input number and returns the next largest integer smaller than or equal to the input parameterparam. It is of theNumbertype.
Example
console.log("floor(-1) = " + Math.floor(-1));console.log("floor(1) = " + Math.floor(1));console.log("floor(-10.54) = " + Math.floor(-10.54));console.log("floor(10.54) = " + Math.floor(10.54));console.log("floor(11.34) = " + Math.floor(11.34));console.log("floor(-0.5) = " + Math.floor(-0.5));