magento price getPrice() value


Question

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?

1
11
2/15/2012 5:18:33 PM

Accepted Answer

Try number format

"<span style=\"font-size:45px\">{" . number_format($pr->getPrice(), 2) . "}</span>"
16
9/20/2009 12:40:00 PM

Why not give this a try...

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

It gives you a currency symbol too.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon