1

I want to change currency decimal symbol from comma to dot for Arabic store view.

Below is the solution that I tried but it's not working for all the pages like category, search page, minicart, checkout cart page its only working with product page.

namespace CustomModule\CustomPriceFormat\Model;
use Magento\Framework\Locale\Bundle\DataBundle;

class Format extends \Magento\Framework\Locale\Format
{
    private static $defaultNumberSet = 'latn';

    public function getPriceFormat($localeCode = null, $currencyCode = null)
    {
        $localeCode = $localeCode ?: $this->_localeResolver->getLocale();
        if ($currencyCode) {
            $currency = $this->currencyFactory->create()->load($currencyCode);
        } else {
            $currency = $this->_scopeResolver->getScope()->getCurrentCurrency();
        }

        $localeData = (new DataBundle())->get($localeCode);
        $defaultSet = $localeData['NumberElements']['default'] ?: self::$defaultNumberSet;

        $format = $localeData['NumberElements'][$defaultSet]['patterns']['currencyFormat']
            ?: ($localeData['NumberElements'][self::$defaultNumberSet]['patterns']['currencyFormat']
                ?: explode(';', $localeData['NumberPatterns'][1])[0]);

        //your main changes are gone here.....
        $decimalSymbol = '.';
        $groupSymbol = ',';

        $pos = strpos($format, ';');
        if ($pos !== false) {
            $format = substr($format, 0, $pos);
        }
        $format = preg_replace("/[^0\#\.,]/", "", $format);
        $totalPrecision = 0;
        $decimalPoint = strpos($format, '.');
        if ($decimalPoint !== false) {
            $totalPrecision = strlen($format) - (strrpos($format, '.') + 1);
        } else {
            $decimalPoint = strlen($format);
        }
        $requiredPrecision = $totalPrecision;
        $t = substr($format, $decimalPoint);
        $pos = strpos($t, '#');
        if ($pos !== false) {
            $requiredPrecision = strlen($t) - $pos - $totalPrecision;
        }

        if (strrpos($format, ',') !== false) {
            $group = $decimalPoint - strrpos($format, ',') - 1;
        } else {
            $group = strrpos($format, '.');
        }
        $integerRequired = strpos($format, '.') - strpos($format, '0');

        $result = [
            //TODO: change interface
            'pattern' => $currency->getOutputFormat(),
            'precision' => $totalPrecision,
            'requiredPrecision' => $requiredPrecision,
            'decimalSymbol' => $decimalSymbol,
            'groupSymbol' => $groupSymbol,
            'groupLength' => $group,
            'integerRequired' => $integerRequired,
        ];       
        //print_r($result);
        //exit;
        return $result;
    }
}

Any solution available that will work for every page?

Thanks

4
  • Do you change like this (prnt.sc/zunurl)?
    – ZealousWeb
    Commented Feb 17, 2021 at 12:18
  • I need like this prnt.sc/zutkui
    – MageDev
    Commented Feb 17, 2021 at 13:07
  • I have one solution but you have to done changes to the core file. Because I can't try overriding that file or anything else.
    – ZealousWeb
    Commented Feb 17, 2021 at 13:12
  • I don't want to change in core file otherwise below solution working vendor/magento/zendframework1/library/Zend/Locale/Data/ar_KW.xml <numbers> <symbols numberSystem="latn"> <decimal>.</decimal> <group>,</group> <list>;</list> <percentSign>%</percentSign> <plusSign>+</plusSign> <minusSign>-</minusSign> <exponential>E</exponential> <superscriptingExponent>×</superscriptingExponent> <perMille>‰</perMille> <infinity>∞</infinity> <nan>NaN</nan> </symbols> </numbers>
    – MageDev
    Commented Feb 17, 2021 at 13:32

1 Answer 1

0

You also need to override the Zend framework for the change to be visible in all pages.

Create file and directory: lib/Zend/Locale/Format.php

Copy the Format.php file from vendor....Zend/Locale/Format.php and modify as follows:

Search for instances of $symbols = Zend_Locale_Data::getList and for each instance, add the following code to override the decimal symbol:

$symbols['decimal'] = '.';

For more details on how to override Zend files using composer, see: How to override a Zend class?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.