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

adding commas to number strings

by Bishma (Beadle)
on Jan 31, 2002 at 22:33 UTC ( [id://142532]=perlquestion: print w/replies, xml ) Need Help??

Bishma has asked for the wisdom of the Perl Monks concerning the following question:

I have a string of numbers I read in from a file. This number is getting very long (into the billons) and it's had to read when it's sent to output. I'd like to be able to set up commas in it.

In otherwords, I'd like 87654321 to be displayed as 87,654,321 without changeing the info stored in the file.

Is there a simple way to do this with printf or something, or could someone come up with a good way to alter it before being printed to the screen? This number is constantly being altered (by millions at a time usually) by other scripts.

Replies are listed 'Best First'.
Re: adding commas to number strings
by wog (Curate) on Jan 31, 2002 at 22:37 UTC
      If I recall correctly its also in the Perl Cookbook, a weighty tome you should seriously think of getting. I read mine all the time :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found