The Wayback Machine - https://web.archive.org/web/20240204103544/https://www.geeksforgeeks.org/lodash-_-round-method/
Open In App
Related Articles

Lodash _.round() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Lodash _.round() method is used to compute numbers rounded to precision.

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

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: In this example, the lodash library’s _.round() method is used to round the number 7.56 to the nearest integer, resulting in the output value of 8.

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: In this example, the lodash library’s _.round() method is applied to round the number 9.005 to 2 decimal places, resulting in the output value of 9.01.

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: In this example, the lodash library’s _.round() method is utilized to round the number 1980 to the nearest hundred (with -2 decimal places), resulting in the output value of 2000.

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 09 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials