Java Check Float is Infinite Number
Tags: float
In this Java core tutorial we learn how to check whether a float value is infinitely large in magnitude or not in Java programming language.
How to check float value is infinite in Java
In Java, with a given float value we can use the Float.isInfinite(float v) static method to check whether the value is a infinite number of not as the following Java program.
CheckFloatInfiniteExample.java
public class CheckFloatInfiniteExample {
public static void main(String... args) {
float floatValue1 = 1.0f / 0.0f;
float floatValue2 = 10.88f;
// Check Float is Infinite Number
boolean result1 = Float.isInfinite(floatValue1);
boolean result2 = Float.isInfinite(floatValue2);
System.out.println("floatValue1 : " + floatValue1);
System.out.println("floatValue1 is infinite : " + result1);
System.out.println("floatValue2 : " + floatValue2);
System.out.println("floatValue2 is infinite : " + result2);
}
}
floatValue1 : Infinity
floatValue1 is infinite : true
floatValue2 : 10.88
floatValue2 is infinite : false
Happy Coding 😊