Java Check Double is Finite Number

Tags: double

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

How to check double value is finite in Java

In Java, with a given double value we can use the Double.isFinite(double d) static method to check if it is a finite floating-point value or not as the example Java code below.

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

        // Check Double is Finite Number
        boolean result1 = Double.isFinite(doubleValue1);
        boolean result2 = Double.isFinite(doubleValue2);

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

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

Happy Coding 😊

Java Convert Double to Hexadecimal String

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

Java Check Double is Infinite Number

Java Convert Double to BigInteger