StrictMath.rint() in Java

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

Syntax:

double java.lang.StrictMath.rint(double a)

This method takes one argument of type double as its parameter. This method returns the double value that is closest in value to the argument and is equal to a mathematical integer.

Note:

1. If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

2. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Parameters: One parameter is required for this method.

a: a value.

Returns: the closest floating-point value to a that is equal to a mathematical integer.

Exceptions: NA

Approach

Java

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

        double a = 1991.89;
        System.out.println(StrictMath.rint(a));
    }
}

Output:

1992.0


No comments:

Post a Comment