Java Data Type How to - Is a Float Not a number








Question

We would like to know how to is a Float Not a number.

Answer

/*from ww w  .  ja v a2  s . c o m*/
public class Main {

  public static void main(String[] args) {
    float f = (float) Math.sqrt(-10);
    boolean b1 = Float.isNaN(f);
    System.out.println(b1);

    Float fObj = new Float(f);
    boolean b2 = fObj.isNaN();
    System.out.println(b2);
  }
}

The code above generates the following result.