Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Separating big numbers with commas

by monkeygirl (Pilgrim)
on Sep 04, 2001 at 23:44 UTC ( #110138=note: print w/replies, xml ) Need Help??


in reply to Separating big numbers with commas

The Perl Cookbook (Recipe 2.17) has just what you need:

my $number = 987654321; print commify($number); sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text }

Update: blakem is right. And besides, my answer is incomplete. For a more complete answer, look here.


Sarah
If Bill Gates can name a company after his "bedroom" problems, I can have a stupid sig that points it out.

Replies are listed 'Best First'.
Re: Re: Separating big numbers with commas
by Anonymous Monk on Aug 07, 2003 at 19:56 UTC
    nice one.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2020-05-30 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (171 votes). Check out past polls.

    Notices?