How do you set a double value to a "non-value"

Two obvious options:

  • Use Double instead of double. You can then use null, but you've changed the memory patterns involved substantially.
  • Use a "not a number" (NaN) value:

    double d = 5.5;
    System.out.println(Double.isNaN(d)); // false
    d = Double.NaN;
    System.out.println(Double.isNaN(d)); // true
    

    Note that some other operations on "normal" numbers could give you NaN values as well though (0 divided by 0 for example).

Share:
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin 28 days

Related