Last Updated : 02 Sep, 2024
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:
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.
// 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.
// 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.
// Requiring the lodash library
const _ = require("lodash");
// Use of _.round()
// method
let gfg = _.round(1980, -2);
// Printing the output
console.log(gfg);
Output:
2000
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4