Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Formatting a number

by Molt (Chaplain)
on Oct 16, 2006 at 12:52 UTC ( #578492=note: print w/replies, xml ) Need Help??


in reply to Formatting a number

You're going to have a lot of people doing a lot of different versions for this.. and here's mine!
#!/usr/bin/perl use strict; use warnings; print (numformat(1000000),"\n"); print (numformat(123),"\n"); print (numformat(12),"\n"); sub numformat { my ($num) = @_; die "'$num' is not a simple integer" unless $num =~ /^\d+$/; while ($num =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/) {}; return $num; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://578492]
help
Chatterbox?
[Your Mother]: :P
[ambrus]: YourMother: my brother told me their cat wants to climb into the dishwasher if they leave the door open. Not when the dishwasher is started, but after it's done washing, because it's still warm and cats like warm.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-12-18 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (491 votes). Check out past polls.

    Notices?