📜  Lodash _.ceil() 方法

📅  最后修改于: 2022-05-13 01:56:51.489000             🧑  作者: Mango

Lodash _.ceil() 方法

_.ceil()方法用于计算四舍五入到精度的数字。

句法:

_.ceil(number, [precision =  0])

参数:此方法接受上面提到的两个参数,如下所述:

  • number:此参数保存要四舍五入的数字。
  • [precision=0]:此参数保存要向上舍入的精度。

返回值:此方法返回四舍五入的数字。

示例 1:这里使用 const _ = require('lodash') 将 lodash 库导入文件。

Javascript
// Requiring the lodash library  
const _ = require("lodash"); 
   
// Use of _.ceil() method 
let gfg = _.ceil(2.4);
         
// Printing the output  
console.log(gfg)


Javascript
// Requiring the lodash library  
const _ = require("lodash"); 
   
// Use of _.ceil() method 
let gfg = _.ceil(3.005, 2);
         
// Printing the output  
console.log(gfg)


Javascript
// Requiring the lodash library  
const _ = require("lodash"); 
   
// Use of _.ceil() method 
let gfg = _.ceil(1680, -2);
         
// Printing the output  
console.log(gfg)


输出:

3

示例 2:

Javascript

// Requiring the lodash library  
const _ = require("lodash"); 
   
// Use of _.ceil() method 
let gfg = _.ceil(3.005, 2);
         
// Printing the output  
console.log(gfg)

输出:

3.01

示例 3:

Javascript

// Requiring the lodash library  
const _ = require("lodash"); 
   
// Use of _.ceil() method 
let gfg = _.ceil(1680, -2);
         
// Printing the output  
console.log(gfg)

输出:

1700