Formatting price in Magento

There are a couple of methods to format price in Magento. The easiest and most used is:

Mage::helper("core")->currency($price, $format, $includeContainer)

Example:

echo Mage::helper("core")->currency(115, true, false)
//if your currency is Euro then output will be: €115.00

Sometimes you don’t need currency symbols in your prices, then you will need something like:

Mage::getModel('directory/currency')->setData("currency_code", Mage::app()->getStore(null)->getCurrentCurrency()->getCode())->format(
    $product->getFinalPrice(), 
    array('display' =>Zend_Currency::NO_SYMBOL), false);

The value for the display can be Zend_Currency::NO_SYMBOL (it will remove the symbol and show only the price) Zend_Currency::USE_SYMBOL (shows the currency symbol before the price), Zend_Currency::USE_SHORTNAME (shows the abbreviation of the currency before the price) or Zend_Currency::USE_NAME (shows the full name of the currency before the price). Example outputs:

Zend_Currency::NO_SYMBOL:         115.00
Zend_Currency::USE_SYMBOL:       €115.00
Zend_Currency::USE_SHORTNAME:  EUR115.00
Zend_Currency::USE_NAME:      EURO115.00

One thought on “Formatting price in Magento”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.