rint() in Java

rint(): This method is available in the Math class of Java.

Syntax:

double java.lang.Math.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. If two double values that are mathematical integers are equally close, the result is the integer value that is even.

Special cases:

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 double value.

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

For Example:

Math.rint(10919.9191) = > It returns 10920.0

Approach

Java

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

        double a = 10919.9191;
        System.out.println(Math.rint(a));

    }
}

Output:

10920.0

No comments:

Post a Comment