The isFinite()
method of the Double
class returns true
if the argument is a finite floating-point value, and returns false
otherwise (for NaN
and infinity
arguments).
public static boolean isFinite(double d)
d
: the value to be tested.In the example below, we define two double values. One is an exponential number, and the other is the result of division by zero. The two double values are tested by the Double.isFinite()
method.
import java.lang.Double;public class Main {public static void main(String args[]){Double d1 = 2E23;Double d2 = d1/0;System.out.println(d1 + " - " + Double.isFinite(d1));System.out.println(d2 + " - " + Double.isFinite(d2));}}