...

View Full Version : How do I supress the display of cents?



jeddi
09-22-2009, 11:20 AM
Hi,

I am retrieving the price from a database and then displaying
it on the page with this code:


<p><b> ...For Only <font color="#ff0000">$<?php echo "$item_price";?></font></b></p>


Now this displays as $37.00!

But I want to know off those zeros, so that I get

$37!

Anyone know a quick and easy way to do this ?

thanks

abduraooft
09-22-2009, 11:41 AM
Try
echo(($item_price*100==($rounded_prize=round($item_price)*100))? $rounded_prize/100: $item_price);

Phil Jackson
09-22-2009, 11:42 AM
$item_price = sprintf("%01.0f", $item_price);

djm0219
09-22-2009, 11:43 AM
Are they always 0s? If you don't care what's on the right side of the decimal you can use:


round($item_price,0)

If you do care about what's after the decimal floor or ceil might be better choices depending on how you want to handle the cents.

jeddi
09-22-2009, 11:56 AM
Thanks for all your help!

And so quick! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum