【问题标题】:Why does JavaScript get this comparison wrong? [closed]为什么 JavaScript 会错误地进行这种比较? [关闭]
【发布时间】:2017-01-28 17:13:02
【问题描述】:

这发生在我正在构建的 Angular 应用程序上。如果用户在 HTML 输入中输入 80,那么这种比较似乎总是错误的。

var x = '80';
var y = 150.9800;

/* Returns incorrect answer */
if (parceFloat(x) < y) {
  return true;
} else {
  return false;
}

【问题讨论】:

  • 方法名是parceFloat还是parseFloat
  • 什么是parceFloat
  • 因为有错字?
  • 有错别字...使用 parseFloat(x) 代替 parceFloat(x)
  • 有错别字吗?

标签: javascript html angularjs


【解决方案1】:

您需要使用 ParseFloat() 而不是 parceFloat() ... parceFloat 不是现有函数。

【讨论】:

  • 请不要回答错字问题,改为标记关闭。
【解决方案2】:

parceFloat()不是函数,函数是parseFloat()

一个简单的错字就是所有的错误。

【讨论】:

  • 请不要回答错字问题,改为标记关闭。
  • 注明。会做的。
猜你喜欢
  • 2021-12-25
  • 1970-01-01
  • 2017-04-28
  • 1970-01-01
  • 2011-11-29
  • 2014-09-02
  • 1970-01-01
  • 1970-01-01
  • 2021-12-08
相关资源
最近更新 更多