Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output a number in money format

Status
Not open for further replies.

ddeham

Programmer
Sep 30, 2005
11
How do I output a number in a money format, like this:
$221,659.20

I can output it like this
printf("Total Payment \$%.2f<BR>",$roundedmonthlypayment * $years * 12);

to get $221659.20, but there are no commas. How do I output with commas? Please help.

Thanks,

Dan
 
Unfortunately Number::Format is not a core module. Here is a solution from the Perl CookBook to add commas:

Code:
sub commify {
    my $text = reverse $_[0];
    $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
    return scalar reverse $text;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top