How to format price in Magento?

Mohan Dave · · 113 Views

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

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

For 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(
    array('display' =>Zend_Currency::NO_SYMBOL), false);

The value for the display can be:

  1. Zend_Currency::NO_SYMBOL : It will remove the symbol and show only the price.

  2. Zend_Currency::USE_SYMBOL : Shows the currency symbol before the price.

  3. Zend_Currency::USE_SHORTNAME : Shows the abbreviation of the currency before the price.

  4. 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

Please login or create new account to add your comment.

You may also like:

Getting the admin panel URLs in Magento

A page in Magento’s administration panel works similar to front-end pages, there is an admin controller for each of all pages in the admin panel. The controller resides in the (...)
Mohan Dave

Most common & frequently used Functions in Magento development

Magento is a very highly effective and thus a little bit challenging to theme CMS. It is designed on the Zend framework, and it often becomes a challenging task to develop or modify (...)
Mohan Dave