On Sun, 10 Oct 2004, Siegfried Heintze wrote:

> So what is the business/accounting convention for displaying currency 
> values in the US? I believe 100, 23432.32 and -53.23 are display as
> 
> $     100.00
> 
> $23,432.32
> 
> $     (53.23)
> 
> I'm not sure if the $ goes outside or inside the parentheses.
 
Outside, I think, but I'm not an accountant or bookkeeper...
 
> Anyway, is there an elegant and slick way to do this in perl? Perhaps 
> there is a special package on CPAN to do this?

Do you have the _Perl Cookbook_? Recipe 2.17 goes over this, at least in 
part:

    sub commify {
        my $text = reverse $_[0];
        $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
        return scalar reverse $text;
    }
 
This may have to be extended for what you're doing, but it's a good 
start. The big insight here is that it's easier to do this on a reversed 
version of the number, then flip it back around once you're done. 
 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to