| Author |
NaN
|
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
Can I compare a variable containing an int to Float.NaN and get the results I intend to get? I get the variable's value from my database and, if it contains erroneous data, I want to skip an if structure that will try to perform arithmatic on it. Will testing it against Float.NaN work? Thanks, g.
|
 |
Bonnie Beach-Morin
Greenhorn
Joined: Jun 13, 2002
Posts: 13
|
|
Yes, technically you can. However, to do so would be somewhat pointless since the result would almost always be false. If the column you retrieve contains a null value, the getInt() method will return 0. Bear in mind that (Float.NaN == Float.NaN) will return false.
|
SJCP2
|
 |
Bonnie Beach-Morin
Greenhorn
Joined: Jun 13, 2002
Posts: 13
|
|
|
By-the-by, what do you consider to be 'erroneous data?'
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Can I compare a variable containing an int to Float.NaN and get the results I intend to get? I suppose it depends what you intend. Probably you want to be using Double.isNaN(double) rather than ==. (Or use Float.isNaN(float) for float.) [ July 02, 2002: Message edited by: Jim Yingst ]
|
"I'm not back." - Bill Harding, Twister
|
 |
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
Bonnie, Erroneous data would be anything written to the 'field' in the database that was corrupted or simply entered wrong. It's a legacy database, and the 'fields' are just characters from a start index to an end index, making it easy for people to be off one index number and overwrite the beginning or end of my 'field' with non-numeric (for my purposes, erroneous) data. ------------------------------------- I did test this in VisualAge for Java's 'scrapbook', the quickest debugging tool I have, and it seemed to work out. But it sounds like the concensus is that I can't rely on those results for all cases. Since the variable needs to be an int before and after this test, the following sounds like the best solution: Jim and Bonnie, do you agree? Thank you! g.
|
 |
 |
|
|
subject: NaN
|
|
|