This is a wonderful little Perl script which is very useful when dealing with monetary database output.

sub docurr($){
local($_)=shift;
$_=sprintf("%.2f",$_);
1 while s/(.*\d)(\d\d\d)/$1,$2/;
$_="\$".$_;
$_;
}


This code is a procedure which takes in one variable"$_" and makes it a float with 2 decimal places using sprintf. Next, The codelooks for an ending of 4 numbers and places a comma in the appropriate position. It continues working its way up the variable one character at a time adding commas when there is a pattern match. When no more pattern matches occur, we cat the results of our while loop with a dollar sign and return the resulting string.

syntax: $printme=&docurr($somenumber);