javascript加数字

我有一个功能

function updateLensTotals() {
  var lensesTotalIs = 0;
  for (z = 0; z < lensesArray.length; z += 7) {
    if (lensesArray[z + 2]) {
      console.log(z + " lensesArray[z+2] is: " + lensesArray[z + 2] + " | ");

      if (isnaN(lensesArray[z + 2])) {
        console.log(lensesArray[z + 2] + " is not a number <br/>");
      } else {
        console.log(lensesArray[z + 2] + " is a number <br/>");
      }
      lensesTotalIs = parseFloat(lensesTotalIs) + lensesArray[z + 2];

      if (isnaN(lensesTotalIs)) {
        console.log(lensesTotalIs + " is not a number <br/>");
      } else {
        console.log(lensesTotalIs + " is a number <br/>");
      }
      console.log(z + " lensesTotalIs: " + lensesTotalIs + " | ");
    }
  }
  jQuery('#lensesTotalDue').html("£" + parseFloat(lensesTotalIs));
  return;
}

这将在控制台中产生

0 lensesArray[z+2] is: 19.99 | 
19.99 is a number <br/>
019.99 is a number <br/>
0 lensesTotalIs: 019.99 | 
cashPaid 0 chequePaid 0  cardPaid 0
0 lensesArray[z+2] is: 19.99 | 
19.99 is a number <br/>
019.99 is a number <br/>
0 lensesTotalIs: 019.99 | 
7 lensesArray[z+2] is: 15.99 | 
15.99 is a number <br/>
19.9915.99 is not a number <br/>
7 lensesTotalIs: 19.9915.99 | 

有一种提供产品价值的表格。我第一次使用19.99,第二次使用19.99和15.99。

首次运行时,一切正常。 19.99是一个数字,可以轻松将其添加到总数中。但是在第二轮中,总数似乎突然被视为文本流。我一定在做些蠢事,但看不到。

谢谢

gush5051 回答:javascript加数字

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3117725.html

大家都在问