零号码会使用ISNAN返回true吗?

发布于 2025-01-31 09:28:15 字数 486 浏览 4 评论 0原文

我和伊斯南有点问题。当数字“零”传递给它时,它会以真实的形式发射,而不是如预期的。

我正在从字符串中解析一个数字,使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒绊 2025-02-07 09:28:15

在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 and Number("") is 0

So when val is equal to 0 you get your loading state

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文