The Wayback Machine - https://web.archive.org/web/20250130165312/https://www.geeksforgeeks.org/javascript-math-round-method/
Open In App

JavaScript Math round() Method

Last Updated : 16 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The JavaScript Math.round() method rounds a number to the nearest integer. It rounds up for decimal values of 0.5 and higher, and down otherwise.

Syntax:

Math.round(value);

Parameters:

  • value: It is the number that you want to round off.

Return Value:

The Math.round() method returns the value of the given number rounded to the nearest integer.

Example 1: To round off a number to its nearest integer. 

javascript
let round =Math.round(-5.8);
console.log("Number after rounding : " + round);

Output
Number after rounding : -6

Example 2: The Math.round() method itself rounds off a negative number when passed as a parameter to it. To round off a negative number to its nearest integer, the Math.round() method should be implemented in the following way: 

javascript
let round =Math.round(-5.8);
console.log("Number after rounding : " + round);

Output
Number after rounding : -6

Example 3: The below program shows the result of the Math.round() method when the parameter has “.5” in decimal. 

javascript
let round =Math.round(-12.5);
console.log("Number after rounding : " + round);
let round1 =Math.round(12.51);
console.log("Number after rounding : " + round1);

Output
Number after rounding : -12
Number after rounding : 13

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers

JavaScript Math round() Method – FAQ

What does the Math.round() method do in JavaScript?

The Math.round() method rounds a number to the nearest integer. If the fractional part of the number is 0.5 or greater, the argument is rounded to the next higher integer. If the fractional part is less than 0.5, the argument is rounded to the next lower integer.

What happens if the argument is exactly halfway between two integers?

If the argument is exactly halfway between two integers (i.e., the fractional part is 0.5), Math.round() rounds to the next higher integer.

Can Math.round() handle negative numbers?

Yes, Math.round() can handle negative numbers. It rounds negative numbers towards zero if the fractional part is less than 0.5, and away from zero if the fractional part is 0.5 or greater.

Can Math.round() handle negative numbers?

Yes, Math.round() can handle negative numbers. It rounds negative numbers towards zero if the fractional part is less than 0.5, and away from zero if the fractional part is 0.5 or greater.

What is the most common use of the Math.round() method?

Most Common Use Cases:

  • Rounding numerical results to the nearest whole number for presentation or further calculation.
  • Ensuring integer values in algorithms that require whole numbers.
  • Simplifying numerical data for readability and reporting.

Next Article

Similar Reads

three90RightbarBannerImg