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

This is useful when we need to do calculations based on the user input. For formatting the entered number in front end we add comma as thousand separator. But problem is when we try to parse it.

e.g, if you try to parseInt (111,222) you ll get the value as 111. To solve this issue we have to use regex and reformat the value.

var numberWithComma = "111,222";
var res = parseFloat( numberWithComma.replace(/,/g, ''));
console.log(res); //111222

Leave a Reply