HomeLanguagesJavascriptLodash _.round() Method

Lodash _.round() Method

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
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS