Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Thousands separator


ggrot - 6:24 pm on Oct 11, 2001 (gmt 0)


I don't remember javascript syntax well, but how 'bout an algorithm:

given string n which is your number and assumming:

loop through the characters in n to find the first occurence of the '.' character. Record it's index in n.

If you dont find it, set the index to be the length of n

starting from the front of n, use the mod 3 of the index of the '.' minus index of the current character to determine if a comma should be inserted behind it. loop through n until you reach the '.' character.


Thread source:: http://www.webmasterworld.com/javascript/8.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com