我如何测试 NaN? [英] How do I test for NaN?
本文介绍了我如何测试 NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
比较 Javascript 中的 NaN 值是否相等
谁能告诉我为什么这不起作用?
Can anyone tell me why this is not working?
if(inbperr == NaN) {
document.getElementById('inbclo').value = "N/A";
}
else {
document.getElementById('inbclo').value = "%" + inbperr;
}
与其返回百分比值或N/A",我希望它返回%NaN".
Instead of returning a percentage value, or "N/A", I want it to return "%NaN".
推荐答案
NaN
是不寻常的:它们不等于任何东西,甚至它们自己.您需要使用 isNaN(inbperr)
来判断一个值是否为 NaN.
NaN
's are unusual: they are not equal to anything, even themselves. You need to use isNaN(inbperr)
to tell whether a value is a NaN or not.
这篇关于我如何测试 NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文