SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Two Decimal Places Not Showing Leading Zeros in Prices Without Cents.

    I'm having some trouble showing leading zeros on numbers that display a whole price. For example, if the price is $175.72, then it shows correctly as $175.72. But if I have an amount of $175.00, the display on the page is only $175. I would like the trailing zeros for prices that have .00 as cents.
    Code:
    if ($show_price) {			
    					$db->setQuery("SELECT REPLACE(REPLACE(C.currency_positive_style,'{symbol}',C.currency_symbol ),'{number}',cast(P.product_price as decimal(19,2))) As pricetext 
                                                 FROM  
                                                 #__virtuemart_product_prices as P 
                                                 LEFT JOIN 
                                                 #__virtuemart_currencies as C on C.virtuemart_currency_id = P.product_currency 
                                                 WHERE P.virtuemart_product_id = '" . $product_id . "'  LIMIT 1 ");
    
    
                                            $price_object = $db->loadObject();
    										
    					//var_dump($pr->prices);
    					
    					$price = $pr->prices['salesPrice'];
    					
    					$price = '<div class="productPrice">Retails'.$price_object->pricetext.round($pr->prices,2).'</div>'.'<div class="salesPrice">Sale:'.round($pr->prices['salesPrice'],2).'</div>';
    It's the 'Sale' price that is not showing trailing zeros.

    What do I do in this situation?

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,798
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Try this: echo sprintf("%1.2f", $money)
    ($money is whatever money value you were wanting to output)
    Hope that helps.

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That was awesome! It worked great! Thank you dresden_phoenix!


Bookmarks

Posting Permissions

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