零号码会使用ISNAN返回true吗?
我和伊斯南有点问题。当数字“零”传递给它时,它会以真实的形式发射,而不是如预期的。
我正在从字符串中解析一个数字,使用parsefloat将其转换为浮点:
let val = parseFloat(value.substring(value.indexOf(";")+1, value.lastIndexOf(";")));
然后将“ val”存储在数组中 这可以很好地工作并按预期工作,但是当我稍后检查以确保使用此代码行实际上是与Isnan的数字: 令dispval =(isnan(val)|| val ==“”)? “值:加载”:“值:” + val;
除非数字为零,否则这很好。如果数字为零,则使用它设置为“值:加载”,
我认为这可能是由于“ 0”也被认为是错误的,但是Isnan的文档的方式使我怀疑
我在做某件事这里错误,或者我们的数据可能被弄糊糊的地方
I'm having a little bit of an issue with IsNaN. When the number 'Zero' is passed to it, it fires off as true, rather than false as expected.
I'm parsing a number from a string, converting it to a float using parseFloat:
let val = parseFloat(value.substring(value.indexOf(";")+1, value.lastIndexOf(";")));
then storing 'val' in an array
This works perfectly fine and works as expected, however when I later check to make sure it is in fact a number with IsNAN, using this line of code:
let DispVal = (isNaN(val) || val== "")? "Value: Loading" : "Value:" + val;
This works perfectly fine, unless the number is zero. If the number is zero it uses it's set to 'Value: Loading'
I had thought this may be due to '0' also being considered false, but the way the documentation for isNaN has me doubting that somewhat
Is there something I'm doing wrong here, or some where our data might be getting mangled
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在JS中,表达式
0 ==“”
是(令人惊讶的)true
。这是因为
“”
被胁迫到一个数字,number(“”)
是0
,因此
val
时等于0
您获得了加载状态In js the result of the expression
0 == ""
is (surprisingly)true
.This is because
""
is being coerced into a number andNumber("")
is0
So when
val
is equal to0
you get your loading state