{"id":187,"date":"2018-09-24T12:46:06","date_gmt":"2018-09-24T12:46:06","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/09\/24\/change-price-decimal-separator-for-arabic-store-in-magento-2\/"},"modified":"2025-05-22T17:18:58","modified_gmt":"2025-05-22T11:48:58","slug":"change-price-decimal-separator-for-arabic-store-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/change-price-decimal-separator-for-arabic-store-in-magento-2\/","title":{"rendered":"Change Price Decimal Separator for Arabic Store in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 stores are shopping platform for customers all over the world. Today we\u2019ll talk about the price decimal separator in Magento 2 for Arabic store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Normally&nbsp; when you show prices in Magento 2 stores, the integer part of the price gets separated using the dot. But when it comes to the Arabic store, it converts the price decimal separator from dot(.) to comma(,). Now due to the change of the separator, the value of the price gets changed. Let\u2019s understand this using an example. Thousand is shown in English store as 1000.00. Switching to an Arabic store or changing the store view to Arabic changes the price decimal separator from dot to comma i.e 1000,00 which actually changes the value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To solve this issue, today I have come up with the custom code to&nbsp;<i><strong>change price decimal separator for Arabic store in Magento 2<\/strong><\/i>. Use the steps below to serve the purpose.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 stores are shopping platform for customers all over the world. Today we\u2019ll talk about the price decimal separator in Magento 2 for Arabic store.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to&nbsp;Change Price Decimal Separator for Arabic Store in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, create di.xml at <strong>app\/code\/Vendor\/Extensionname\/etc\/di.xml&nbsp;<\/strong>and add below code into it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;preference for=\"Magento\\Framework\\Locale\\Format\" type=\"Vendor\\Extensionname\\Model\\Format\" \/>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now create&nbsp;model file at&nbsp;<strong>app\/code\/Vendor\/Extensionname \/Model\/Format.php&nbsp;<\/strong>and put below code there.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extensionname\\Model;\nuse Magento\\Framework\\Locale\\Bundle\\DataBundle;\nclass Format extends \\Magento\\Framework\\Locale\\Format\n{\n    private static $defaultNumberSet = 'latn';\n    public function getPriceFormat($localeCode = null, $currencyCode = null)\n    {\n        $localeCode = $localeCode ?: $this->_localeResolver->getLocale();\n        if ($currencyCode) {\n            $currency = $this->currencyFactory->create()->load($currencyCode);\n        } else {\n            $currency = $this->_scopeResolver->getScope()->getCurrentCurrency();\n        }\n        $localeData = (new DataBundle())->get($localeCode);\n        $defaultSet = $localeData['NumberElements']['default'] ?: self::$defaultNumberSet;\n        $format = $localeData['NumberElements'][$defaultSet]['patterns']['currencyFormat']\n            ?: ($localeData['NumberElements'][self::$defaultNumberSet]['patterns']['currencyFormat']\n                ?: explode(';', $localeData['NumberPatterns'][1])[0]);\n        \/\/your main changes are gone here.....\n        $decimalSymbol = '.';\n        $groupSymbol = ',';\n        $pos = strpos($format, ';');\n        if ($pos !== false) {\n            $format = substr($format, 0, $pos);\n        }\n        $format = preg_replace(\"\/[^0\\#\\.,]\/\", \"\", $format);\n        $totalPrecision = 0;\n        $decimalPoint = strpos($format, '.');\n        if ($decimalPoint !== false) {\n            $totalPrecision = strlen($format) - (strrpos($format, '.') + 1);\n        } else {\n            $decimalPoint = strlen($format);\n        }\n        $requiredPrecision = $totalPrecision;\n        $t = substr($format, $decimalPoint);\n        $pos = strpos($t, '#');\n        if ($pos !== false) {\n            $requiredPrecision = strlen($t) - $pos - $totalPrecision;\n        }\n        if (strrpos($format, ',') !== false) {\n            $group = $decimalPoint - strrpos($format, ',') - 1;\n        } else {\n            $group = strrpos($format, '.');\n        }\n        $integerRequired = strpos($format, '.') - strpos($format, '0');\n        $result = [\n            \/\/TODO: change interface\n            'pattern' => $currency->getOutputFormat(),\n            'precision' => $totalPrecision,\n            'requiredPrecision' => $requiredPrecision,\n            'decimalSymbol' => $decimalSymbol,\n            'groupSymbol' => $groupSymbol,\n            'groupLength' => $group,\n            'integerRequired' => $integerRequired,\n        ];       \n        return $result;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the steps in proper way and you\u2019ve nailed the issue of price decimal separator of Arabic store in Magento 2 with ease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 stores are shopping platform for customers all over the world. Today we\u2019ll talk about the price decimal separator in Magento 2 for Arabic&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":15595,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/187\/revisions\/15595"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}