Magento 2: How to get current Currency and symbol in PHTML File?
please note that creating this with objectManager, not the best practice
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currencysymbol = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currency = $currencysymbol->getStore()->getCurrentCurrencyCode();
getCurrentCurrencyCode() Gives the Currency code and not the symbol but you were helpful rest I figured -
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currencyCode = $storeManager->getStore()->getCurrentCurrencyCode();
$currency = $objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
echo $currencySymbol = $currency->getCurrencySymbol(); ?>
Another way to approach this would be to use the Pricing\Helper, this will both give you the currency symbol and format the number to the correct decimal place.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$value = 1000; // or whatever value you have in your template
$formattedCurrencyValue = $priceHelper->currency($value, true, false);
Although, I believe it's bad practice calling ObjectManager from within a template, for something as simple as getting the correct currency symbol you would imagine it would be more straight forward.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$currencyCode = $storeManager->getStore()->getCurrentCurrencyCode();
$currency = $objectManager->create('\Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
echo $currencySymbol = $currency->getCurrencySymbol();
?>
Now you will not face the fatal error