in reply to Problem adding comma & removing decimal
sub addComma { my $number = reverse int shift; $number =~ s/(\d{3})(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $number; }
Partial credit goes to the Perl Cookbook, and the rest to int instead of a RE.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem adding comma & removing decimal
by Steny (Sexton) on Jun 05, 2004 at 06:01 UTC | |
|
Re^2: Problem adding comma & removing decimal
by bart (Canon) on Jun 05, 2004 at 06:17 UTC | |
by davido (Cardinal) on Jun 05, 2004 at 07:08 UTC |