Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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; }


Comment on Re: Formatting a number
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-07-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls