开发者

Test for NaN in java

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜