Skip to content
Related Articles

Related Articles

Lodash _.round() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 09 Sep, 2020

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.round() method is used to compute number rounded to precision.

Syntax:

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

Parameters: This method accepts two parameters as mentioned above and described below:

  • number: This parameter holds the number to round.
  • [precision = 0]: This parameter holds the precision to round to.

Return Value: This method returns the rounded number.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.

Javascript




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

Output:

8

Example 2:  

Javascript




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

Output:

9.01

Example 3:  

Javascript




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

Output:

2000

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!