Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I supress the display of cents?

    Hi,

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

    PHP 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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    PHP Code:
    echo(($item_price*100==($rounded_prize=round($item_price)*100))? $rounded_prize/100$item_price); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    $item_price sprintf("%01.0f"$item_price); 
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,294
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Are they always 0s? If you don't care what's on the right side of the decimal you can use:

    PHP Code:
    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.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for all your help!

    And so quick!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •