in reply to How do I add commas to a number?
Adding just a wee tiny bit to vroom's and Fastolfe's answers...
This ditty accepts a list of numbers for commification, like so:
my($minC, $maxC, $medC) = commify($min, $max, $med);
or so:
my @numsC = commify(@nums);
sub commify { my @output; for(@_){ my $input = $_; $input = reverse $input; $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g; $input = reverse $input; push @output, $input; } return @output; }
Originally posted as a Categorized Answer.
|
---|
In Section
Seekers of Perl Wisdom