1

How to change the price format to Indian price format in Magento 2

Example: Price display like 453,453, want to display in the indian manner like 4,53,450

satyavir
  • 61
  • 7

2 Answers2

0
  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);
  1. deploy and `rm -rf var/cache/*

  2. Done

Example: A price previously displayed like 453,453, will now display in the Indian manner like 4,53,453.

satyavir
  • 61
  • 7
0

@satyavir, I suggest you to do not change the core files of the magento, create your own module add en.xml file.

Well magento 2 is now supporting INR also, still you need modification then you can follow your above steps.

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62