webkul
webkul

Reputation: 2864

magento price getPrice() value

function getDescriptionHtml($tpl, $p){
    $out = "";
    $pr = $p["product"];

    if(Mage::getStoreConfig('featuredproducts/displayoptions/title') == 'description'){
        $out .= "<ins><h4>{$pr->getName()}</h4></ins>";
    }
    $out .= "<span class=\"description\"".
            (!Mage::getStoreConfig('featuredproducts/displayoptions/description') ?
                    "style=\"display:none;\""
                :
                    ""
            )
            .">{$p['description']}</span>";
    $out .= "<ins><div>".
            (Mage::getStoreConfig('featuredproducts/displayoptions/price') ?
                    "<span style=\"font-size:45px\">{$pr->getPrice()}</span>"
                :
                    ""
            )       
            ."".
            (Mage::getStoreConfig('featuredproducts/displayoptions/bnb') ?
                    "<div><button style=\"postion:relative;margin-left:80px;margin-top:140px\" class=\"form-button\" onclick=\"setLocation('{$p["url"]}')\"><span>{$tpl->__('Buy Now')}</span></button></div>"
                :
                    "")
            ."
            </div></ins>";
    return $out;        
}

Per the code shown, when I'm using $pr->getPrice() its output looks like 299.0000, but I want it to be like 299.00. How can I do this?

Upvotes: 11

Views: 79318

Answers (5)

R T
R T

Reputation: 4549

Mage::helper('core')->currency($_product->getFinalPrice(),true,false);
  • "true" for price format.
  • "false" for no html.

this i did in Magento 1.7.0.2

Upvotes: 20

Alan Lapington
Alan Lapington

Reputation: 1346

Why not give this a try...

Mage::helper('core')->currency($pr->getPrice());

It gives you a currency symbol too.

Upvotes: 43

dan
dan

Reputation: 29

or

sprintf("%0.2f",$_product->getFinalPrice());

Upvotes: 2

Marlon Creative
Marlon Creative

Reputation: 3846

Use "round" as number format doesn't always work correctly, depending on the location and currency formatting:

<span style=\"font-size:45px\">{" . round($_product->getFinalPrice(),2) . "}</span>

Upvotes: 1

Yannick Motton
Yannick Motton

Reputation: 35971

Try number format

"<span style=\"font-size:45px\">{" . number_format($pr->getPrice(), 2) . "}</span>"

Upvotes: 16

Related Questions