VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-math-round-function-2/

⇱ JavaScript Math.round( ) function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Math.round( ) function

Last Updated : 22 May, 2023

JavaScript Math.round( ) function is used to round the number passed as a parameter to its nearest integer. 

Syntax:

Math.round(value)

Parameters:

  • value: The number to be rounded to its nearest integer.

Example 1: Rounding Off a number to its nearest integer

To round off a number to its nearest integer, the math.round() function should be implemented in the following way: 

Output:

Number after rounding : 6

Example 2: Rounding Off a negative number to its nearest integer

The Math.round() function 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() function should be implemented in the following way: 

Output:

Number after rounding : -6

Example 3: Math.round() function, when a parameter has ".5" as a decimal

Below program shows the result of Math.round() function when the parameter has ".5" as a decimal. 

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:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

Comment