Monday, December 8, 2025
HomeLanguagesJavaStrictMath rint() Method in Java

StrictMath rint() Method in Java

The rint() is the inbuilt method of StrictMath class in Java which is used to get the double value which is closest in value to the argument and is equal to an integer. It returns the integer value which is even when the two double values that are integers are equally close to the value of the given argument. It returns the same as argument when the argument value is already equal to the integer and it returns the same as the argument when the argument is NaN or an infinity or positive zero or negative zero.
Syntax: 

public static double rint(double num)

Parameters: The method accepts single parameter num of double type which is to be converted using this method.
Return Value: The method returns the closest floating point value that is equal to a integer.
Examples : 

Input: num =72.2
Output: 72.0

Below programs illustrate the rint() method:
Program 1: 

java




// Java program to illustrate the
// java.lang.StrictMath.rint()
 
import java.lang.*;
 
public class Geeks {
    public static void main(String[] args)
    {
 
        // Get a double number
        double num1 = 87.1;
 
        // Convert the double number using rint() method
        double rint_Value = StrictMath.rint(num1);
 
        // Print the result
        System.out.println(" The Integer value closest to "
                         + num1 + " = " + rint_Value);
 
        // Get a double number
        double num2 = 65.9;
 
        // Convert the double number using rint() method
        rint_Value = StrictMath.rint(num1);
 
        // Print the result
        System.out.println(" The Integer value closest to "
                         + num1 + " = " + rint_Value);
    }
}


Output: 

The Integer value closest to 87.1 = 87.0 
The Integer value closest to 87.1 = 87.0

 

Program 2: 

java




// Java program to illustrate the
// java.lang.StrictMath.rint()
 
import java.lang.*;
 
public class Geeks {
 
    public static void main(String[] args)
    {
 
        // Get a double number
        double num1 = -65.5;
 
        // Convert the double number using rint() method
        double rint_Value = StrictMath.rint(num1);
 
        // Print the result
        System.out.println(" The Integer value closest to "
                         + num1 + " = " + rint_Value);
 
        // Get a double number
        double num2 = -42.7;
 
        // Convert the double number using rint() method
        rint_Value = StrictMath.rint(num1);
 
        // Print the result
        System.out.println(" The Integer value closest to "
                         + num1 + " = " + rint_Value);
    }
}


Output: 

The Integer value closest to -65.5 = -66.0 
The Integer value closest to -65.5 = -66.0

 

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32429 POSTS0 COMMENTS
Milvus
103 POSTS0 COMMENTS
Nango Kala
6803 POSTS0 COMMENTS
Nicole Veronica
11945 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12015 POSTS0 COMMENTS
Shaida Kate Naidoo
6934 POSTS0 COMMENTS
Ted Musemwa
7189 POSTS0 COMMENTS
Thapelo Manthata
6883 POSTS0 COMMENTS
Umr Jansen
6869 POSTS0 COMMENTS