0

Does anyone have a good method for formatting a numeric value as an American currency value in Perl? I'm not finding anything in my searches.

Thank you for your consideration.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by KevinADC
0

There are a number of currecny formatting modules on CPAN. The are also conversion modules to convert between currencies. If you are simply wanting to format an existing USA monetary value into a fixed format you can role your own function.

$foo = 1999999.99;
print USA_Format($foo);

sub USA_Format { 
(my $n = shift) =~ s/\G(\d{1,3})(?=(?:\d\d\d)+(?:\.|$))/$1,/g; 
return "\$$n USD"; 
}

I think the above regexp was taken from the Perl FAQs 4 section of the perl documentation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.