To Format integer to Comma seperated integer


Some times we need to show numbers as comma separated values while showing the values to the users and while he is trying to edit the number we need to show as number for that on blur event we need to format the number with comma and the remove the comma on focus of the control using Onfocus event.

(3) Means it will separate 3 numbers in comma for EX 888,888,888 etc.,

var rgx = /(\d+)(\d{3})/;

function CommaFormatted(amount)
amount=amount.replace(/^0+/, '');
amount += '';
x = amount.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return x1 + x2;

//To remove the comma for the variables
function RemoveCommaFormatted(amount)
amount= amount.replace(/,/g,"");
return amount;



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: