Site icon MageComp Blog

How to change currency symbol position left to right in Magento 2

Magento 2 How to change currency symbol position left to right1

A currency symbol is basically a graphical notation that represents particular currency instead of writing the whole name beside price. For business, it’s extremely important to specified But the potion of this graphical notation varies by currency.
Take a look at following example:

Many currencies in the English-speaking world and Latin America place it before the amount like this $10.00 but n many European countries such as France, Germany, Greece, Scandinavian countries, the symbol is usually placed after the amount like this 10.00€.
Also, the decimal separator follows countries and currency standards.

But Magento fails to change position when you change the Currency from the backend. That’s why one of our client and friend asked us to do same. To help more people and to fix this issue quickly, we decided to published an article on our blog.

Create another ‘events.xml’ file inside your folder.
app\code\Vendor\Extension\etc\events.xml

<pre class="lang:default decode:true">
<?xml version="1.0"?>    
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="currency_display_options_forming">
        <observer name="vendor_extension_change_currency_position" instance="Vendor\Extension\Model\Observer\Changecurrencyposition" />
    </event>
</config>
</pre>

Now you need to create another observer file inside extension folder.
app\code\Vendor\Extension\Model\Observer

<pre class="lang:default decode:true">
<?php        
namespace Vendor\Extension\Model\Observer;    
use Magento\Framework\Event\ObserverInterface;    
class Changecurrencyposition implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {    
        $currencyOptions = $observer->getEvent()->getCurrencyOptions();    
        $currencyOptions->setData('position', \Magento\Framework\Currency::RIGHT);  
        return $this;
    }    
}
</pre>

Lastly, Run the following command and you are done.

php bin/magento setup:upgrade

Yes, you have successfully changed the position of currency symbol in store frontend.

Comment down below if you face any issue while using this code.

Happy Swapping!

Exit mobile version