Subscribe to Subscribers

Resources » TypeScript » Scripting Languages » Javascript

To Format integer to Comma seperated integer


Posted Date:     Category: Javascript    
Author: Member Level: Gold    Points: 15



Hi,

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;
}



Regards
JK





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...

Feedbacks      

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.


    Next Resource: Display alert box in asp.net
    Previous Resource: Check all rows at table header
    Return to Resources
    Post New Resource
    Category: Javascript


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    To seperate Numbers by comma  .  Number formatiing in java script  .  Java script number formating  .  

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.