Format US Dollar with commas using Perl


I am having a heck of a time finding how to do this. Right now I have

sprintf("%.2f", $amount)

which prints the amount with 2 decimal places. How do I get Perl to print with the 2 decimal places along with commas?

So I can get 35,456.08 instead of 35456.08.


There are a number of modules on CPAN that do this. You can try Locale::Currency::Format

use Locale::Currency::Format;

my $amount = 35456.08;
print currency_format('usd',$amount,FMT_SYMBOL);
print "\

This produces: