cancel
Showing results for 
Search instead for 
Did you mean: 

Currency symbol position

Currency symbol position

Hello!

 

I need to move currency symbol position to the left.

 

I found vendor\magento\zendframework1\library\Zend\Currency.php file.

 

Here we could see 

 

protected $_options = array(
        'position'  => self::STANDARD,
        'script'    => null,
        'format'    => null,
        'display'   => self::NO_SYMBOL,
        'precision' => 2,
        'name'      => null,
        'currency'  => null,
        'symbol'    => null,
        'locale'    => null,
        'value'     => 0,
        'service'   => null,
        'tag'       => 'Zend_Locale'
    );

So, if I replace

 

 

'position'  => self::STANDARD

with

 

 

'position'  => self::LEFT

I will get exactly what I need.

 

But I did not find the way how I could to override zend core files.

 

Could any one help me with this?

Or maybe here exist other way? Such as setup "left" position for

self::STANDARD

 "position" option?

 

Thank you.

 

5 REPLIES

Re: Currency symbol position

Hi,

 

Go through below link it will help you to change currency symbol position:

 

http://www.templatemonster.com/help/magento-how-to-change-currency-symbol-position.html#gref

 

https://php.quicoto.com/how-to-change-currency-position-in-magento/

 

If this post is fulfill you solution then please mark as accept.

 

Thanks,

Dibyajyoti

Re: Currency symbol position

I found a rough solution.

 

I overrid \Magento\Directory\Model\Currency::formatTxt($price, $options = []) function.

Now it looks like this:

public function formatTxt($price, $options = [])
    {
        if(!isset($options['position'])) {
            $options['position'] = 32;
        }
        if (!is_numeric($price)) {
            $price = $this->_localeFormat->getNumber($price);
        }
        /**
         * Fix problem with 12 000 000, 1 200 000
         *
         * %f - the argument is treated as a float, and presented as a floating-point number (locale aware).
         * %F - the argument is treated as a float, and presented as a floating-point number (non-locale aware).
         */
        $price = sprintf("%F", $price);
        return $this->_localeCurrency->getCurrency($this->getCode())->toCurrency($price, $options);
    }

Thank you.

Re: Currency symbol position

 

Re: Currency symbol position

 

Ok, On Magento 2 same thing can do in: vendor\magento\zendframework1\library\Zend\Locale\Data\ 

 

<currencyFormats numberSystem="latn">
    <currencyFormatLength>
        <currencyFormat type="standard">
            <pattern>#,##0.00 ¤</pattern>
        </currencyFormat>
    </currencyFormatLength>
</currencyFormats>

Find your currency code file and change accordingly.

 

Or if you want to install extension go through below link:

 

https://mage2.pro/t/topic/355 (Not free)

 

Regards,

 

Re: Currency symbol position

@vlad_bro : thank for your solution .

@Dibyajyoti M : thank , but i think modify library code is not a good way.

 

For any guys looking for solution about currency positon :

- Make your custom module:

app/code/Your_Vendor/Currency
├── Model/
│   ├── Currency.php
├── etc/
│    ├── di.xml/
│    ├── module.xml/
├── registration.php
├── composer.json

- Declare your custom model in di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Directory\Model\Currency" type="Your_Vendor\Currency\Model\Currency" />
</config>

- Your custom model : Currency.php

class Currency extends \Magento\Directory\Model\Currency
{
    // Constants for defining the position of the currencysign
    const STANDARD = 8;
    const RIGHT    = 16;
    const LEFT     = 32;
    /**
     * @param float $price
     * @param array $options
     * @return string
     */
    public function formatTxt($price, $options = [])
    {
        if (!is_numeric($price)) {
            $price = $this->_localeFormat->getNumber($price);
        }
        if(!isset($options['position'])) {
            $options['position'] = self::RIGHT;
        }
        /**
         * Fix problem with 12 000 000, 1 200 000
         *
         * %f - the argument is treated as a float, and presented as a floating-point number (locale aware).
         * %F - the argument is treated as a float, and presented as a floating-point number (non-locale aware).
         */
        $price = sprintf("%F", $price);
        return $this->_localeCurrency->getCurrency($this->getCode())->toCurrency($price, $options);
    }
}

Please google more about custom module in Magento 2 for 

│    ├── module.xml/
├── registration.php
├── composer.json

 Happy codding !!!