Lodash _.floor() 方法
_.floor()方法用于计算向下舍入到精度的数字,这意味着它向下舍入到下限值。
句法:
_.floor(number, [precision = 0])
参数:此方法接受上面提到的两个参数,如下所述:
- number:此参数保存要向下舍入的数字。
- [precision = 0]:此参数保存要向下舍入的精度。
返回值:此方法返回四舍五入的数字。
示例 1:这里使用 const _ = require('lodash') 将 lodash 库导入文件。
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.floor() method
let gfg = _.floor(2.4);
// Printing the output
console.log(gfg)
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.floor() method
let gfg = _.floor(0.525, 2);
// Printing the output
console.log(gfg)
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.floor() method
let gfg = _.floor(1680, -2);
// Printing the output
console.log(gfg)
输出:
2
示例 2:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.floor() method
let gfg = _.floor(0.525, 2);
// Printing the output
console.log(gfg)
输出:
0.52
示例 3:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// Use of _.floor() method
let gfg = _.floor(1680, -2);
// Printing the output
console.log(gfg)
输出:
1600