Sunday 23 June 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...