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.