I'm wondering if there is a way to test for NaN in java. The code below is returning NaN where it should be returning "NA".
if (tempAlloc == Double.NaN) {
tv4.setText("NA");
} else {
tv4.setText(customFormat("###.#%",
Double.toString(tempAlloc)));
}
Usa Double.isNaN(tempAlloc). It returns true, when the argument is NaN and false otherwise.
This is implemented by checking if the argument is not equal to itself (a unique property of NaN values):
boolean isNaN == tempAlloc != tempAlloc;
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