Java Check Float is Finite Number

Tags: float

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

How to check float value is finite in Java

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

public class CheckFloatFiniteExample {
    public static void main(String... args) {
        float floatValue1 =  1.0f / 0.0f;
        float floatValue2 = 10.88f;

        // Check Float is Finite Number
        boolean result1 = Float.isFinite(floatValue1);
        boolean result2 = Float.isFinite(floatValue2);

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

        System.out.println("floatValue2 : " + floatValue2);
        System.out.println("floatValue2 is finite : " + result2);
The output as below.
floatValue1 : Infinity
floatValue1 is finite : false
floatValue2 : 10.88
floatValue2 is finite : true

Happy Coding 😊

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

Java Check Float is Infinite Number