I'm a bit of a novice to Java, and I've written some code that doesn't give the output I'm expecting.
if (!"".equals(S_USD_EXCH_RATE)
&& !S_USD_EXCH_RATE.equalsIgnoreCase("---")) {
exchRate = Double.parseDouble(S_USD_EXCH_RATE);
}
if (S_NW < 0 || (S_FA / S_NW) > 4)
return -1;
else if ((S_NW * exchRate) > 75000000.0 && (S_FA / S_NW) < 1.5)
return 3;
else if ((S_NW * exchRate) > 25000000.0 && (S_FA / S_NW) < 2)
return 2;
else if (S_NW == 0)
return 0;
else if ((S_NW * exchRate) >= 1 && (S_FA / S_NW) < 4)
return 1;
else
return 1;
When S_NW
is blank, a value of 1
is returned, when it's supposed to be 0
. I can't figure out why as when S_NW == 0
(which should cover the situation of no value as well, as I understand), an output of0
should be returned. Any ideas?
As per the comments: I was under the impression java knew 0 to be either the number value of 0 or no value. Is that not correct? I have a program provided by an external body written in java where you can create new objects, you get the option of creating a number object, date, string etc. The S_NW object is a number. The program allows the object to have no data assigned to it, hence the term blank, or no value. Hope that helps.
As per further comment:
I don't know what 'Number' refers to exactly, the program is closed source. On your information you've provided, I can add another line to tell it what to do in the case of NULL and see if that's any better. From the comments, it should fix it.
Further to comments:
Yes that's all I have to work with. The suggested S_NW != null check gives me an exception error, incomparable types: double and
I guess that makes S_NW a double
data type
Further information:
I have tried wrapping the code in if S_NW = Double.NaN {}; else return 0
and I have replaced else if (S_NW == 0)
with else if (S_NW == 0 || S_NW == 0.0 || S_NW == Double.NaN)
and I still get the output of 1 on both occasions. This doesn't make any sense as those two edits contradict each other, suggesting S_NW
is both == Double.NaN
and not equal to Double.NaN
which can't be right. Unless I'm being really thick?