Magento 2 format price currency


Magento 2 format price currency – It is very simple to format price currency in Magento 2. You can use object manager or factory method to format price in currency. Here in this article we are going to explain how you can use format price currency function in magento 2.x.


Magento 2 format price Currency With Symbol Example

Magento 2 format price currency

Here is an example to format price in Any currrency with symbol-

With Currency Symbol

The below example will format price with currency symbol-

Magento 2 format price Currency Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
    $price =  99.99;
    $currencyFormattedPrice = $priceHelper->currency($price, true, false);

The above example will format price with currency symbol with two decimal.

WithOut Currency Symbol

If you want to format currency Symbol you can do it as below-

Magento 2 format price Currency Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
    $price =  99.99;
    $currencyFormattedPrice = $priceHelper->currency($price, array('display' => Zend_Currency::NO_SYMBOL));

The above example will format currency without symbols.


Advertisements

Add Comment

📖 Read More