A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-round-method/ below:

Lodash _.round() Method - GeeksforGeeks

Lodash _.round() Method

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:

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


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