Java Math round() Method

Facebooktwitterredditpinterestlinkedinmailby feather

The round() method of Java Math class returns a long or an int value that is closest to the argument and is rounded to positive infinity.

Syntax:

  1. public static int round(float a)
  2. public static long round(double a)

Parameters:

The parameters ‘a’ represents the floating –point number whose rounded value is to be determined.

Return Value:

The round() method returns the rounded value of the argument to its nearest long or int value.

Special cases are as follows:

  • The result is 0, if the argument is NaN.
  • The result is Long.MIN_VALUE, if the argument is negative infinity or any value less or equal to Long.MIN_VALUE.
  • The result is Long.MAX_VALUE, if the argument is positive infinity or any value greater or equal to Long.MAX_VALUE.

 Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output:

Facebooktwitterredditpinterestlinkedinmailby feather