FW: LA.pm: Perl is money

Arkadiy Sudarikov asudarikov at xceed.com
Wed Oct 24 19:08:35 CDT 2001



-----Original Message-----
From: Arkadiy Sudarikov 
Sent: Wednesday, October 24, 2001 5:08 PM
To: 'brobison at deimos.org'
Subject: RE: LA.pm: Perl is money


I deal with a lot of money (no, really, about 61,000,000.00 a week.) So,
sprintf '%.2f', $money works better for me...

-----Original Message-----
From: brobison at warmachine.deimos.org
[mailto:brobison at warmachine.deimos.org]
Sent: Wednesday, October 24, 2001 2:23 PM
To: Arkadiy Sudarikov
Subject: Re: LA.pm: Perl is money


On Wed, Oct 24, 2001 at 03:56:24PM -0500, Arkadiy Sudarikov wrote:
> Hi. Does anyone have a sprintf (regex?) string that formats money amounts?
> 
> Like, it takes a number (float) and reformats it, maybe even placing
decimal
> comma every three digits from the right and pads and approximates cents,
> making it a string...
> 
> Thanks, ya all,
> Arkadiy

sub commify_format {
  my $number = shift;
  $number = sprintf('%9.2f',$number);
  $number = reverse $number;
  $number =~ s#(\d\d\d)(?=\d)(?!\d*\.)#$1,#g;
	return scalar reverse $number;
}

-- 
Barry Robison - brobison at deimos.org

The formula of my happiness A Yes, a No, a straight line, a goal.



More information about the Losangeles-pm mailing list