Page 1 of 1

Currency Assistance, pls for quick sec of your time

Posted: Mon Aug 22, 2011 5:33 pm
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.

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

Posted: Mon Aug 22, 2011 5:57 pm
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));
?>

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

Posted: Mon Aug 22, 2011 7:02 pm
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.

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

Posted: Mon Aug 22, 2011 8:54 pm
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.

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

Posted: Mon Aug 22, 2011 9:33 pm
by califdon
danjapro wrote:You guys are genuis, no matter what they say about you.....
That's what they pay us for! :wink:

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

Posted: Mon Aug 22, 2011 11:16 pm
by twinedev
califdon wrote: That's what they pay us for!
Where do I sign up for that? LOL