In JavaScript / jQuery what is the best way to convert a number with a comma into an integer?

David picture David · Nov 3, 2010 · Viewed 21.1k times · Source

I want to convert the string "15,678" into a value 15678. Methods parseInt() and parseFloat() are both returning 15 for "15,678." Is there an easy way to do this?

Answer

SLaks picture SLaks · Nov 3, 2010

The simplest option is to remove all commas: parseInt(str.replace(/,/g, ''), 10)