Commify and Dollarfy





5
Date Submitted Wed. Oct. 11th, 2006 7:58 AM
Revision 1 of 1
Scripter ctiggerf
Tags PHP | String
Comments 3 comments
Two very usefull functions to have around.

(note: dollarfy requires commify to work)

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);
}
 

Chris Falzone

www.eadexchange.com

Comments

Comments number_format
Wed. Oct. 11th, 2006 11:14 AM    Helper BrandonReese
  Comments Oops
Mon. Oct. 16th, 2006 7:21 AM    Scripter ctiggerf
Comments SPAM?
Fri. Oct. 27th, 2006 9:11 AM    Helper bright

Voting