I'm reading some currency values from a database and I need to display them
in a vertical column using an HTML table. These values need a leading "$".
They also need a comma for the thousands separator. 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.

 

Anyway, is there an elegant and slick way to do this in perl? Perhaps there
is a special package on CPAN to do this?

 

I'm wondering if you could do something like this:

 

perl -e ' $v = 1000000.23; $v =~ s/([0-9][0-9][0-9])([0-9])/\1,\2/g; print
"$v\n"; '

 

This does not quite work, however, because the commas are added starting
from the left, not the right. Is there a way to start matching from the
right instead of the left?

 

  Thanks,

    Siegfried

 

Reply via email to