Parse String to Double.NaN

java, nan, string

Solution

You can pass `+NaN` or `-NaN` or `NaN` to `valueOf()` and have it return a NaN. The documentation gives the full details.

Problem

i want to let users edit a field with double data. I want to allow `Double.NaN` (to void values). Is there a generic way (a predefined string) that is parsed to `Double.NaN` from the method `Double.valueOf(String)` without checking it in the background? There is a special char looking like a diamond with a question mark in it (in HTML) that acts like NaN, but - well - the users wont find that on their keys.

Original source