Magento – Get currency rate by currency code

currencycurrency-ratesmagento2

I need to currency rate by currency code in magento 2.

$currency =  $objectManager->get('Magento\Framework\Pricing\PriceCurrencyInterface');
$currencySymbol = $currency->getRate('USD');

I tried above code it returns fatal error.

Best Answer

I reckon you should use Magento\Directory\Model\Currency class instead of Magento\Framework\Pricing\PriceCurrencyInterface.

On top of that, I suggest you never use the object manager directly and use dependency injection instead.