开发者

Test for NaN in java

开发者 https://www.devze.com 2023-02-18 23:12 出处:网络
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\".

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(customForma开发者_JAVA百科t("###.#%",
                        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;
0

精彩评论

暂无评论...
验证码 换一张
取 消