How To Get Magento 2 Currency Rate By Currency Code

I am going to build the extension for Magento 2 and would like to retrieve currency rate by given currency code

You can use class – “currencyFactory” and “getAnyRate” method to retrieve the rate

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currencyFactory =$_objectManager->create('\Magento\Directory\Model\CurrencyFactory');
$currencyRates = $currencyFactory->create()->load("USD")->getAnyRate("JPY");
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments