Currency Assistance, pls for quick sec of your time

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
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Currency Assistance, pls for quick sec of your time

Post by danjapro »

I currently have my code string set as

Code: Select all

<?php echo ShushAppHelper::displayCurrency($deal->price, -3)?>
This displays the currency as $10.00.
I am trying to get print $10.
I tried these

Code: Select all

<?php echo ShushAppHelper::displayCurrency('$f-2', $deal->price)?>
<?php echo ShushAppHelper::displayCurrency(’%n2’, $deal->price)?>
<?php echo ShushAppHelper::displayCurrency(floor($deal->price,-2))?>
None worked.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Currency Assistance, pls for quick sec of your time

Post by twinedev »

Well, if we had more code, and know what things like displayCurrency() does and what $deal->price contains, could probably give a more efficient answer.

As is though, given what you did, just have to do a hack on it...

Code: Select all

<?php 

	function wholeNumber($strFormattedNumber,$intDecPlaces = 0) {
		$strStripped = preg_replace('/[^-0-9.]/','',$strFormattedNumber);
		return '$'.number_format((float)$strStripped,$intDecPlaces);
	}

	echo wholeNumber(ShushAppHelper::displayCurrency($deal->price, -3));
?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Currency Assistance, pls for quick sec of your time

Post by califdon »

Do you want to NOT show cents, even if the $deal->price is not in even dollars? Or will this system never handle cents? See, the issue is that you are using a function called displayCurrency() which returns a value formatted to show 2 decimal places, so you have to either change that function or reformat it, as twinedev suggested. Changing what you enter as input to the function can never change what it does inside the function.
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: Currency Assistance, pls for quick sec of your time

Post by danjapro »

twinedev,

Appreciate the snippet by miles, simple fix, worked like charm. Truly, correct. I add twinedev code to the decimal re-write, wokred all acorss the app.
You guys are genuis, no matter what they say about you.....

Respect, twinedev much respect.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Currency Assistance, pls for quick sec of your time

Post by califdon »

danjapro wrote:You guys are genuis, no matter what they say about you.....
That's what they pay us for! :wink:
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Currency Assistance, pls for quick sec of your time

Post by twinedev »

califdon wrote: That's what they pay us for!
Where do I sign up for that? LOL
Post Reply