How can I parse a string with a comma thousand separator to a number?

user1540714 picture user1540714 · Jul 26, 2012 · Viewed 112.5k times · Source

I have 2,299.00 as a string and I am trying to parse it to a number. I tried using parseFloat, which results in 2. I guess the comma is the problem, but how would I solve this issue the right way? Just remove the comma?

Answer

Sam picture Sam · Jul 26, 2012

Yes remove the commas:

parseFloat(yournumber.replace(/,/g, ''));