Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: formatting numbers

by TOD (Friar)
on Nov 08, 2007 at 03:02 UTC ( [id://649626]=note: print w/replies, xml ) Need Help??


in reply to formatting numbers

sub number_format { my $num = shift; return $num unless $num; return undef unless $num =~ /^[0-9\.+-]+$/; $num =~ s/^([\+-])?//; my $sign = $1; $num =~ s/\.([0-9]+)$//; # must come before the call to abs(), be +cause here my $dec = $1; # a floating point value is still regard +ed as a string by perl, even if it's 0.00. $num = abs $num; $num = reverse $num; $num =~ s/(\d{3})/$1\,/g; $num =~ s/\.$//; $num = reverse $num; $num .= ".$dec" if $dec; $num = "$sign$num" if $sign; $num; }
--------------------------------
masses are the opiate for religion.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found