JS: Add / Remove Comma formatting dollar amounts in the thousands. Ex: 1,000
Useful for grabbing input values to format then display, remove the comma and convert back to number to do math.
#js #snippet
var removeComma = function(str){
return str.replace(/,/g, '').trim();
}
var addComma = function(str){
return str.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}