Currency Format delete cents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ardoa
Forum Newbie
Posts: 7
Joined: Tue Oct 05, 2010 6:49 am

Currency Format delete cents

Post by ardoa »

Hello i need give a currency format without cents
i have this 1.000.00 i need this $1.000
how can i edit the code below to delete the cents???

Code: Select all

// format money from numeric values
        function format_money ($value, $decimal = true) {
                $value = str_replace(",","",$value);
                if (!is_numeric($value)) return "0.00";
                $aux = split("\.",$value);
                $cents = (count($aux) > 1)    ? array_pop($aux)   : "";
                $cents = (strlen($cents) > 2) ? substr($cents,0,2): $cents;
                $cents = str_pad($cents,2,"0",STR_PAD_RIGHT);
                $value = implode("",$aux);
                $formated_money = ($decimal) ? $value.".".$cents : $value ;
                return $formated_money;
        }
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Currency Format delete cents

Post by twinedev »

replace

Code: Select all

$formated_money = ($decimal) ? $value.".".$cents : $value ;
with

Code: Select all

$formated_money = $value ;
???

Why not just use the built in number_format($number,0) ?
Post Reply