vForums Support Banner Image



 

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

[Avatar]

Posts: 3,269
Status: Offline
Gender: Male
Joined: 16th Dec 2007
Reputation: 16%  



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

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


Smiley
Back to Top - Link to Post - Last edit: 10th Jun 08 at 11:15am by Wrighty

Image
Printable View

All times are GMT+1 :: The current time is 11:03am
Page generated in 0.5236 seconds
with 15 Database Queries and 4 cache files
This Forum is Powered By vForums
Create a Forum for Free