Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How do I add commas to a number?

by ybiC (Prior)
on Jul 14, 2002 at 12:19 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-08-19 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?