Java.lang Package Classes

Java StrictMath - round() Method



The java.lang.StrictMath.round() method returns the value of argument rounded to its nearest integer. In special cases it returns the following:

  • If the argument is NaN, the result is 0.
  • If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.

Syntax

public static int round(float a)

Parameters

a Specify a floating point value to be rounded.

Return Value

Returns the value of argument rounded to its nearest int value.

Exception

NA.

Example:

In the example below, round() method returns the value of argument rounded to its nearest int value.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.round(48.45f));   
  System.out.println(StrictMath.round(48.55f));   
 }
}

The output of the above code will be:

48
49

❮ Java.lang - StrictMath