skip to Main Content

I am using Magento 2.2.3. my default currency is INR, but it shows in the wrong format:

enter image description here

But it should be ₹77,65,000.00. How do we correct price format? Currently its wrong… like USD.

2

Answers


  1. You can set the currency format by following code.

    <?php
        $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of Object Manager
        $priceHelper = $objectManager->create('MagentoFrameworkPricingHelperData'); // Instance of Pricing Helper
        $price =  1000; //Your Price
        $formattedPrice = $priceHelper->currency($price, true, false);
    ?>
    
    Login or Signup to reply.
    1. File path: vendor/magento/zendframework1/library/Zend/Locale/Data/en.xml

    2. On line number 3353, under section currencyFormat and type = "standard", change the pattern from <pattern>¤#,##0.00</pattern> to <pattern>¤ #,##,##0.00</pattern>

    3. Still, on PDP page and cart page summary the price format does not change because the prize format is coming from the JS in which Magento using a RegExp function for only US price format.
      For that, please change the code in the below file.

      File path: vendor/magento/module-catalog/view/base/web/js/price-utils.js (First extend this file in your theme directory and do the respected changes)

      Under the function formatPrice below this line comment all the line in the respective function.

      i = parseInt(
          amount = Number(Math.round(Math.abs(+amount || 0) + 'e+' + precision) + ('e-' + precision)),
          10
      ) + '';
      

      And add this set of code below the above line.

      var x=i;
      x=x.toString();
      var afterPoint = '';
      if(x.indexOf('.') > 0)
          afterPoint = x.substring(x.indexOf('.'),x.length);
      x = Math.floor(x);
      x=x.toString();
      var lastThree = x.substring(x.length-3);
      var otherNumbers = x.substring(0,x.length-3);
      if(otherNumbers != '')
          lastThree = ',' + lastThree;
      var response = otherNumbers.replace(/B(?=(d{2})+(?!d))/g, ",") + lastThree + afterPoint;
      return pattern.replace('%s', response);
      
    4. deploy and `rm -rf var/cache/*

    And then you’re done. For Example: A price previously displayed like 453,453, will now display in the Indian manner like 4,53,453.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search