3

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 ?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Digital fortress
  • 737
  • 8
  • 18
  • 31

1 Answers1

17

Remove the commas, obviously:

parseFloat(value1.replace(/,/g,''))
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592