StrictMath.round(float) in Java

StrictMath.round(float): This method is available in java.lang.StrictMath class of Java.

Syntax:

int java.lang.StrictMath.round(float a)

This method takes one argument of type float as its parameter. This method returns the closest int to the argument, with ties rounding to positive infinity.

Note:

1. If the argument is NaN, the result is 0.

2. If the argument is negative infinity or any value less than orequal to the value of Integer.MIN_VALUE, the result isequal to the value of Integer.MIN_VALUE.

3. If the argument is positive infinity or any value greater than orequal to the value of Integer.MAX_VALUE, the result isequal to the value of Integer.MAX_VALUE.

Parameters: One parameter is required for this method.

a: a floating-point value to be rounded to an integer.

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

Exceptions: NA

Approach

Java

public class StrictMathroundfloat {
    public static void main(String[] args) {

        float a = 119.56f;
        System.out.println(StrictMath.round(a));
    }
}

Output:

120


StrictMath.round(double)



No comments:

Post a Comment