Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: "Commifying" a number

by BrowserUk (Patriarch)
on Dec 12, 2002 at 16:03 UTC ( [id://219351]=note: print w/replies, xml ) Need Help??


in reply to "Commifying" a number

#! perl -sw use strict; my $re_commify = qr/^([+-]?\d+?)(\d{3})(?>((?:,|\.|$)\d?))(.*)$/; for (-12..7) { my $num= eval("-123456789E$_"); printf '%31.13f commified becomes ', $num; 1 while $num =~ s/$re_commify/$1,$2$3$4/; printf "%s\n", $num; } __END__ c:\test>commify -0.0001234567890 commified becomes -0.000123456789 -0.0012345678900 commified becomes -0.00123456789 -0.0123456789000 commified becomes -0.0123456789 -0.1234567890000 commified becomes -0.123456789 -1.2345678900000 commified becomes -1.23456789 -12.3456789000000 commified becomes -12.3456789 -123.4567890000000 commified becomes -123.456789 -1234.5678900000000 commified becomes -1,234.56789 -12345.6789000000010 commified becomes -12,345.6789 -123456.7890000000000 commified becomes -123,456.789 -1234567.8899999999000 commified becomes -1,234,567.89 -12345678.9000000000000 commified becomes -12,345,678.9 -123456789.0000000000000 commified becomes -123,456,789 -1234567890.0000000000000 commified becomes -1,234,567,890 -12345678900.0000000000000 commified becomes -12,345,678,900 -123456789000.0000000000000 commified becomes -123,456,789,000 -1234567890000.0000000000000 commified becomes -1,234,567,890,000 -12345678900000.0000000000000 commified becomes -12,345,678,900,000 -123456789000000.0000000000000 commified becomes -123,456,789,000,000 -1234567890000000.0000000000000 commified becomes -1.23456789e+015 c:\test>

Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Replies are listed 'Best First'.
Re: Re: "Commifying" a number
by mojotoad (Monsignor) on Dec 13, 2002 at 06:46 UTC
    Ah, yes. Indeed. Perhaps this should be obfuscated into a script called three_mile_island.pl ?

    ;)
    Matt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found