3

I want currency Symbol using currency code in magento 2. so any one help me?

I have tried below code but I got error Class Magento\Directory\Model\CurrencyFact‌​ory does not exist

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$currencyManager = $_objectManager->create('Magento\Directory\Model\CurrencyFac‌​tory')->create()->ge‌​tResource(); 
echo $currencySymbol = $currencyManager->getCurrencyCodeFromToCurrency($_code);
9
  • I want currency Symbol using currency code in magento 2. so any one help me? Dec 7, 2016 at 7:49
  • 1
    @Marius This boy only wants currency code that's why voted this for reopen, may be some one can easily answer this question Dec 7, 2016 at 7:51
  • @MurtuzaZabuawala if you say you can answer this I will reopen it, but this looks like a poorly asked question to me.
    – Marius
    Dec 7, 2016 at 7:52
  • 2
    @SusantaKumarDas here is your answer magento.stackexchange.com/questions/130102/… Dec 7, 2016 at 7:55
  • <?php $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $currencyManager = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->getResource(); echo $currencySymbol = $currencyManager->getCurrencyCodeFromToCurrency($_code); ?> I am use this code but not working. Dec 7, 2016 at 8:01

6 Answers 6

4
<?php
class Customclass{
    protected $storeManager;
    protected $currencySymbol;
    protected $localeCurrency;
    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Directory\Model\Currency $currencySymbol,
        \Magento\Framework\Locale\CurrencyInterface $localeCurrency
    ) {
        $this->_storeManager = $storeManager;
        $this->currencySymbol = $currencySymbol;
        $this->localecurrency = $localeCurrency;
    }

    public function getStoreCurrency(){
        $currencycode = $this->_storeManager->getStore()->getCurrentCurrencyCode();
        return $this->localecurrency->getCurrency($currencycode)->getSymbol();
    }
}
2
  • Are this serious? All of that just to get a "$"/"R$"/"€"/etc symbol? Oct 9, 2020 at 14:07
  • Maybe a PR with a helper to do that could be good, let's try.. Oct 9, 2020 at 14:08
0

There is no method available of

you can use like this to get currency symbol.

 $om = \Magento\Framework\App\ObjectManager::getInstance();
 $currencyManager = $om->get('Magento\Directory\Model\Currency'); 
 echo $currencyManager->getCurrencySymbol();

or you set currency symbol using below code.

$priceHelper = $om->get('Magento\Framework\Pricing\Helper\Data');
echo $priceHelper->currency($price, true, false);
0

To get the symbol:

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_Symbol = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($_code);
echo $_Symbol->getCurrencySymbol();
1
0

To get Currency symbol use the following code into your phtml or your block.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currencysymbol = $objectManager->get('Magento\Directory\Model\Currency')->getCurrencySymbol();

or replace get with create sometime I have faced this issue according to the location of code like block, controller, Model or phtml.

$currencysymbol = $objectManager->create('Magento\Directory\Model\Currency')->getCurrencySymbol();
0

this is the code

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
echo $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($_code)->getCurrencySymbol();
0
0

To get the Currency Symbol :

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

$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');

$price =  1000; //Your Price

$formattedPrice = $priceHelper->currency($price, true, false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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