Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How do I add commas to a number?

by ybiC (Prior)
on Jul 14, 2002 at 12:19 UTC ( [id://181569]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181569]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found