Hi we have one US website and one CA website

However, for some reason I have to find a Magento function for currency conversion. I have CAD want to transfer to USD in the US store view. I did set up the Magento currency conversion rate table as well.

So, how do I call this function out to do the conversion?


2 Answers 2


To convert currency you can use Magento\Framework\Pricing\PriceCurrencyInterface.

Module’s block class:

namespace VendorName\ModuleName\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
    protected $_storeManager;
    protected $_currency;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Directory\Model\Currency $currency,
        \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrencyInterface,
        array $data = []
        $this->_storeManager = $storeManager;
        $this->_currency = $currency;        
        $this->_priceCurrencyInterface = $priceCurrencyInterface;
        parent::__construct($context, $data);

     * Covert currency code
     * @return It return price according to current store from base currency
    public function convertPrice($amount,$currency)
        $store = $this->_storeManager->getStore()->getStoreId();
        return $priceCurrencyObject->convert($amount, $store, $currency);

To get other currncy info storewise:

    // retutn Currency Symbol:

    // return store base currency code

    // return default store currency code

    // return array of installed currencies for the scope

    // return current currency rate

Template (.phtml) file:

echo $block->convertPrice($amount,$currency);

Hope this helps!


To set the currency based on the website you have to set the default currency by website from configurations.

Go to

Admin->Stores->Configuration->General->Currancy Setup

Select the US Website from the Store View selector from top left of the Configuration page and set the

Default Display Currency to US Dollar and for Allowed Currencies only select the US Dollar. Check this screenshot.

enter image description here

Procced the same for the CA Website.

Clear the cache and check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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