Currency Format Problem

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 Problem

Post by ardoa »

Hi Guys, i need any help regarding how to put a currency format without CENTS.
thanks in advnce, here is the code:

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;
	}
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Currency Format Problem

Post by buckit »

what is an example if your input? what is an example of your desired output? what is your actual output?
ardoa
Forum Newbie
Posts: 7
Joined: Tue Oct 05, 2010 6:49 am

Re: Currency Format Problem

Post by ardoa »

ACTUAL IS $ 100.00

AND

I NEED $ 100
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Currency Format Problem

Post by internet-solution »

use (int) or intval()
ardoa
Forum Newbie
Posts: 7
Joined: Tue Oct 05, 2010 6:49 am

Re: Currency Format Problem

Post by ardoa »

internet-solution wrote:use (int) or intval()
Thanks, but where i need to it in the code???
Post Reply