Completely Free .NET word API

Resources » TypeScript » Scripting Languages » Javascript

To Format integer to Comma seperated integer

Updated: Category: Javascript
Author: Member Level: GoldPoints: 15


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;


Did you like this resource? Share it with your friends and show your love!

Responses to "To Format integer to Comma seperated integer"

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


Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India