最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Javascript adding numbers with commas - Stack Overflow

programmeradmin3浏览0评论

I have four HTML fields, I grab their values and add them, in an equation that looks like this:

Total = Number(value1) + Number(value2) + Number(value3) + Number(value4)

Now some of the values might be equal to 1,078.00, I get NaN as a result. What should I do ?

I have four HTML fields, I grab their values and add them, in an equation that looks like this:

Total = Number(value1) + Number(value2) + Number(value3) + Number(value4)

Now some of the values might be equal to 1,078.00, I get NaN as a result. What should I do ?

Share Improve this question edited Dec 3, 2012 at 8:44 Jean-François Corbett 38.5k30 gold badges142 silver badges189 bronze badges asked Dec 3, 2012 at 8:12 Digital fortressDigital fortress 7378 gold badges18 silver badges31 bronze badges 2
  • Please check I think you are adding any string in expression. – Vijay Verma Commented Dec 3, 2012 at 8:15
  • this can help to some extent stackoverflow./questions/10473994/… – ankur Commented Dec 3, 2012 at 8:18
Add a ment  | 

1 Answer 1

Reset to default 17

Remove the mas, obviously:

parseFloat(value1.replace(/,/g,''))
发布评论

评论列表(0)

  1. 暂无评论