function commify ($str) {
        $n = strlen($str);
        if ($n <= 3) { $return=$str; }
        else {
        $pre=substr($str,0,$n-3);
        $post=substr($str,$n-3,3);
        $pre=commify($pre);
        $return="$pre,$post";
        }
        return($return);
}
 

function dollarfy ($num,$dec) {
        $format="%.$dec" . "f"
        $number=sprintf($format,$num);
        $str=strtok($number,".");
        $dc=strtok(".");     
        $str=commify($str);
        $return="\$".$str;
        if ($dec!=0) { $return = $return . "." . $dc; }
        return($return);
}