Lodash _.floor() Method
Lodash _.floor() method is used to compute numbers rounded down to precision means it rounded down to the floor value.
Syntax:
_.floor(number, [precision = 0])
Parameters:
This method accepts two parameters as mentioned above and described below:
- number: This parameter holds the number to round down.
- [precision = 0]: This parameter holds the precision to round down to.
Return Value:
This method returns the rounded-down number.
Example 1: In this example, the code uses the Lodash library to round down the number 2.4 to the nearest integer using the _.floor()
method.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.floor() method let gfg = _.floor(2.4); // Printing the output console.log(gfg) |
Output:
2
Example 2: In this example, the code requires the Lodash library and uses the _.floor
method to round a number (0.525) to a specified number of decimal places (2) and displays the result in the console.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.floor() method let gfg = _.floor(0.525, 2); // Printing the output console.log(gfg) |
Output:
0.52
Example 3: In this example, the code requires the Lodash library and employs the _.floor
method to round a number (1680) to the nearest multiple of 100 (specified by -2) and displays the result in the console.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.floor() method let gfg = _.floor(1680, -2); // Printing the output console.log(gfg) |
Output:
1600
Contact Us