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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.