Close

Java - Math.rint() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Method:

public static double rint(double a)

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.


Examples


package com.logicbig.example.math;

public class RintExample {

public static void main(String... args) {
value(5.475);
value(8.91);
value(2.5);
value(3.5);
value(0.00);
value(Double.POSITIVE_INFINITY);
}

private static void value(double a) {
double result = Math.rint(a);
System.out.printf("Math.rint(%s) = %.2f%n", a, result);
}

}

Output

Math.rint(5.475) = 5.00
Math.rint(8.91) = 9.00
Math.rint(2.5) = 2.00
Math.rint(3.5) = 4.00
Math.rint(0.0) = 0.00
Math.rint(Infinity) = Infinity




See Also