Java Math.round() method

21 Mar 2025 | 2 min read

The java.lang.Math.round() is used round of the decimal numbers to the nearest value. This method is used to return the closest long to the argument, with ties rounding to positive infinity.

Syntax

Parameter

Return

  • If the argument is positive or negative number, this method will return the nearest value.
  • If the argument is not a number (NaN), this method will return Zero.
  • If the argument is positive Infinity or any value less than or equal to the value of Integer.MIN_VALUE, this method will return Integer.MIN_VALUE.
  • If the argument is negative Infinity or any value less than or equal to the value of Long.MAX_VALUE, this method will return Long.MAX_VALUE.

Example 1

Output:

 80 

Example 2

Output:

 -84 

Example 3

Output:

 -9223372036854775808 

Example 4

Output:

 9223372036854775807 

Example 5

Output:

 0 
 
Next TopicJava Math