[php] Format price in the current locale and currency

I use :

$product->getPrice();

to get the unformatted price that I can calculate "quantity X price" with ajax.

I want to reformat the total in the current locale and currency. How can I do that?

This question is related to php magento

The answer is


This is a charming answer. Work well on any currency which is selected for store.

$formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);

$formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false);

Unformatted and formatted:

$price = $product->getPrice();
$formatted = Mage::helper('core')->currency($price, true, false);

Or use:

Mage::helper('core')->formatPrice($price, true);

By this code for formating price in product list

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

try this:

<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>

For formatting the price in another currency than the current one:

Mage::app()->getLocale()->currency('EUR')->toCurrency($price);