I have the following code...
if (Price_Foreign != Double.NaN) { output.Append(spacer); output.Append(String.Format("{0,-10:C} USD",Price_Foreign)); }
Which outputs:
NaN USD
What gives?
I'm using Double.NaN to indicate that the value doesn't exist, and shouldn't be output.
NaN and Double. NaN: “A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.
All numeric operations with NaN as an operand produce NaN as a result. Reason behind this is that NaN is unordered, so a numeric comparison operation involving one or two NaNs returns false.
Unlike all other possible values in JavaScript, it is not possible to use the equality operators (== and ===) to compare a value against NaN to determine whether the value is NaN or not, because both NaN == NaN and NaN === NaN evaluate to false . The isNaN() function provides a convenient equality check against NaN .
Perhaps you are looking for the IsNaN
static function?
Try something like this:
if (!Double.IsNaN(Price_Foreign)) { output.Append(spacer); output.Append(String.Format("{0,-10:C} USD",Price_Foreign)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With