Return to Snippet

Revision: 65483
at December 6, 2013 05:48 by supawaza


Initial Code
var removeComma = function(str){
    return str.replace(/,/g, '').trim();
}

var addComma = function(str){
    return str.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

Initial URL

                                

Initial Description
Add / Remove comma for number 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.

Initial Title
Adding/remove commas in digits

Initial Tags
js, number

Initial Language
JavaScript