Java Check Double is Infinite Number

Tags: double

In this Java core tutorial we learn how to check whether a double value is an infinite value or not in Java programming language.

How to check double value is infinite in Java

In Java, with a given double value we can use the Double.isInfinite(double v) static method to check if it is an infinite value or not as the following example Java program.

CheckDoubleInfiniteExample.java

public class CheckDoubleInfiniteExample {
    public static void main(String... args) {
        double doubleValue1 =  1.0 / 0.0;
        double doubleValue2 = 11.07;

        // Check Double is Infinite Number
        boolean result1 = Double.isInfinite(doubleValue1);
        boolean result2 = Double.isInfinite(doubleValue2);

        System.out.println("doubleValue1 : " + doubleValue1);
        System.out.println("doubleValue1 is infinite : " + result1);

        System.out.println("doubleValue2 : " + doubleValue2);
        System.out.println("doubleValue2 is infinite : " + result2);
    }
}
The output as below.
doubleValue1 : Infinity
doubleValue1 is infinite : true
doubleValue2 : 11.07
doubleValue2 is infinite : false

Happy Coding 😊

Java Convert Double to Hexadecimal String

Java Check Double is Not-a-Number (NaN)

Java Check Double is Finite Number

Java Convert Double to BigInteger