vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Database of Codes/Hacks/Mods :: Code Submissions :: Add Comma - View Topic
Topic Rating: *****
Printable View
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Add Comma (10th Jun 08 at 10:13am UTC)
This code will change long numbers into numbers will commas in.. eg: 12121212 = 12,121,212 {Smile}

<script>
/*Add Commas - Snippet*/

function comma_it(n){
    n += '';
    x = n.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;
}
</script>


Example:

<script>
alert(comma_it('121211221'))
</script>


{Smile}
 Printable View

All times are GMT+0 :: The current time is 7:51am
Page generated in 0.0914 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums