Magento 2 get currency symbol by code

Magento 2 get currency symbol

Magento 2 get currency symbol using code can be we do from Magento currency Interface. In default, magento will give all currency from configuring admin. To set the configuration see here.In frontend all the allowed currencies are displayed. So we can get the current currency code directly from store manager.To get the current currency code click here. While doing custom functionalities, we need to get the currency symbol of the code. I have seen lot of articles like here using object manager to get the currency symbol from currency code. The best way to get magento 2 currency symbol from code is given below.

Code for Magento 2 get currency symbol by code

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function __construct(
		\Magento\Framework\Locale\CurrencyInterface $localeCurrency
	)
{
    $this->localecurrency = $localeCurrency;
}

public function getCurrencySymbol($currencycode)
{
    return $this->localecurrency->getCurrency($currencycode)->getSymbol();
}
}

In helper or model declare the currency interface class in construct function and pass the currency code as the parameter to return the currency currency symbol. The above code getCurrencySymbol function returns the currency symbol using the code. If the currency code doesn’t have the symbol it returns the code directly.

1 Comment

You can post comments in this post.


  • Nice article. You saved my time

    Karthick 5 months ago Reply


No Comments yet, your thoughts are most welcome