Sunday, June 23, 2019

html - Javascript adding numbers with commas



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 ?


Answer



Remove the commas, obviously:



parseFloat(value1.replace(/,/g,''))

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...