Read More
Read More
Menu Close

    Convert price from current currency magento2

    To convert price from current currency to base currency to can use following method:

    public function convertPrice($amount = 0, $store = null, $currency = null)
    {
    	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    	$priceCurrencyObject = $objectManager->get('Magento\Framework\Pricing\PriceCurrencyInterface'); //instance of PriceCurrencyInterface
    	$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface'); //instance of StoreManagerInterface
    	if ($store == null) {
            $store = $storeManager->getStore()->getStoreId(); //get current store id if store id not get passed
        }
        $rate = $priceCurrencyObject->convert($amount, $store, $currency); //it return price according to current store from base currency
    
        //If you want it in base currency then use:
        $rate = $this->_priceCurrency->convert($amount, $store) / $amount;
        $amount = $amount / $rate;
    	
    	return $priceCurrencyObject->round($amount);//You can round off to it or you can return it in its original form
    }

    Here, $amount is the amount to which you want to convert.

    $store is the store id, from which store’s base currency you want to convert.

    $currency is the currency to whom  you want to convert, if you passed null then it takes current currency.

    Searching for an experienced
    Magento 2 Company ?
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top