How can I output my numbers with commas added?
[email protected] (pizza)
| Newsgroups | perl.perlfaq.workers |
|---|---|
| Message-ID | <[email protected]> |
i offer the following regex in replacement to Mr. Goldberg's:
s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
--------------------------------
#!/usr/bin/perl -l
$_ = "-10,000000";
s/([+-])?(\d{1,3})(?=(\d{3})+)/$1$2,/g;
print;
--------------------------------
it should handle explicit leading negation/addition as well as existing commas
pizza