Magento2 – Get Formatted Price By Currency Symbol
If having an issue in getting the formatted price in magento2 in the desired currency then no need to worry about this. Here, we will see how to get the formatted price with the currency symbol in Magento2.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$currencyModel = $objectManager->create('Magento\Directory\Model\Currency'); // Instance of Currency Model
$price = 500; //Your Price
//get currency symbol by currency code
$currencyCode = 'USD';
$currencySymbol = $currencyModel->load($currencyCode)->getCurrencySymbol();
$precision = 2; // for displaying price decimals 2 point
//get formatted price by currency
$formattedPrice = $currencyModel->format($price, ['symbol' => $currencySymbol, 'precision'=> $precision], false, false);
?>
Formatted price is $500.00
Categories:
Magento2
View Comments (2)
Comment or Ask a Question
Quick Links