javascript parseFloat '500,000' returns 500 when I need 500000

How would it be a nice way of handling this?

I already thought on removing the comma and then parsing to float.

Do you know a better/cleaner way?

Thanks


Solution 1:

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

Solution 2:

I don't know why no one has suggested this expression-

parseFloat( theString.replace(/[^\d\.]/g,'') );

Removes any non-numeric characters except for periods. You don't need custom functions/loops for this either, that's just overkill.