in reply to "Commifying" a number
Another way to do it... (but only works on newer perls with lookbehind.) I didn't realize it was a FAQ when I needed to do it. The theme is the same though. Repeatedly make substitutions until there are none left to make.
1 while ( s/(?<!\b)(\d{3})(?:,|$)/,$1/ ); # Explained 1 while ( # Repeat until no more matches are made. s/(?<!\b)(\d{3}) # Match any three digits not preceded by a word +break. (?:,|$) # That come immediately before a comma or the en +d. /,$1/x # And insert a comma before them. );
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: "Commifying" a number
by BrowserUk (Patriarch) on Dec 12, 2002 at 19:27 UTC | |
by sauoq (Abbot) on Dec 13, 2002 at 00:49 UTC |