I have below code

$currencyManager        = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->getResource(); 
echo $currencySymbol    = $currencyManager->getCurrencyCodeFromToCurrency('USD');

It gives fatal error

Fatal error: Call to undefined method Magento\Directory\Model\ResourceModel\Currency::getCurrencyCodeFromToCurrency()

Can anybody guide me to get Currency Symbol from Currency Code?

up vote 2 down vote accepted

It should be:

$currency = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
$currencySymbol = $currency->getCurrencySymbol();

It would be beter to use CurrencyRepository but it's not yet implemented in Magento 2.

We can do this using Constructor injection.

/**
 * @var \Magento\Framework\Locale\CurrencyInterface
 */
protected $_localeCurrency

public function __construct(
    \Magento\Framework\Locale\CurrencyInterface $localeCurrency
)
{
    $this->_localecurrency = $localeCurrency;
}

Now you can use below code in your function to get currency symbol.

$this->_localecurrency->getCurrency($currencycode)->getSymbol();

To get the symbol:

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_Symbol = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($_code);
echo $_Symbol->getCurrencySymbol();
  • Your code doesn't work. $_code is not defined. – J Plana Jan 25 '17 at 20:52

Instead of using object manager try with currency interface

public function __construct(
        \Magento\Framework\Locale\CurrencyInterface $localeCurrency
    )
{
    $this->localecurrency = $localeCurrency;
}
$this->localecurrency->getCurrency($currencycode)->getSymbol();

For full code please refer here http://webhintsexplorer.com/magento-2-get-currency-symbol-by-code/

It also works like this:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();

$storeManager =$objectManager>get('\Magento\Store\Model\StoreManagerInterface');
$currency = $objectManager->get('\Magento\Directory\Model\Currency');

$store = $storeManager->getStore();

print_r($store->getWebsite()->getBaseCurrency()->getCurrencySymbol());

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.