Magento2:Format priceHow to change currency format in Magento 2?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlHow to change currency format in Magento 2?main.CRITICAL: Plugin class doesn't existMagento2 - How to use Magento_Catalog/js/price-box to format price in template?Format price decimal pointsMagento 2.2.5: Overriding Admin Controller sales/orderChanging price formatMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMsrpPriceCalculator Exception

Would a 7805 5v regulator drain a 9v battery?

How do I become a better writer when I hate reading?

Bash function: Execute $@ command with each argument in sequence executed separately

Scaling an object to change its key

Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?

What is this airplane that sits in front of Barringer High School in Newark, NJ?

Time at 1G acceleration to travel 100 000 light years

Why was New Asgard established at this place?

Leaving job close to major deadlines

How to prevent cables getting intertwined

How can I ping multiple IP addresses at the same time?

In windows systems, is renaming files functionally similar to deleting them?

King or Queen-Which piece is which?

Basic power tool set for Home repair and simple projects

Credit card validation in C

How to make all magic-casting innate, but still rare?

Harmonic Series Phase Difference?

Are there examples of rowers who also fought?

How to avoid offending original culture when making conculture inspired from original

How is linear momentum conserved in circular motion?

Is it a bad idea to have a pen name with only an initial for a surname?

Operator currying: how to convert f[a,b][c,d] to a+c,b+d?

Explicit song lyrics checker

If the mass of the Earth is decreasing by sending debris in space, does its angular momentum also decrease?



Magento2:Format price


How to change currency format in Magento 2?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlHow to change currency format in Magento 2?main.CRITICAL: Plugin class doesn't existMagento2 - How to use Magento_Catalog/js/price-box to format price in template?Format price decimal pointsMagento 2.2.5: Overriding Admin Controller sales/orderChanging price formatMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMsrpPriceCalculator Exception






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a website where currency is displayed in the format xx,xx CHF. I want to it to the format CHF xx.xx



I got the solution to position the currency symbol by refering the below link.



https://magecomp.com/blog/change-currency-symbol-position-left-right-magento-2/



Added the below files



app/code/Vendor/Module/etc/events.xml



<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="vendor_extension_change_currency_position" instance="VendorModuleModelObserverChangecurrencyposition" />
</event>
</config>


appcodeVendorModuleModelObserverChangecurrencyposition



<?php 
namespace VendorModuleModelObserver;
use MagentoFrameworkEventObserverInterface;
class Changecurrencyposition implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)

$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', MagentoFrameworkCurrency::LEFT);
return $this;




This worked for me to change the position of price symbol.



Now I need to change the price separator from ',' to '.'
I found a solution here



Added the below files to change the price formatter.
app/code/Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoFrameworkLocaleFormat" type="VendorModuleModelFormat" />
</config>


appcodeVendorModuleModelFormat.php



 <?php
namespace venorModuleModel;

use MagentoFrameworkLocaleBundleDataBundle;

class Format extends MagentoFrameworkLocaleFormat

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,
];
return $result;




But it is working only in view page not in listingpage, minicart etc



Can anyone provide a solution for this??










share|improve this question
























  • Share your code for better understand.

    – Chirag Patel
    Jun 10 at 6:54











  • @ChiragPatel I have added the code. Can you please provide a solution?

    – Vindhuja
    Jun 10 at 7:30

















1















I have a website where currency is displayed in the format xx,xx CHF. I want to it to the format CHF xx.xx



I got the solution to position the currency symbol by refering the below link.



https://magecomp.com/blog/change-currency-symbol-position-left-right-magento-2/



Added the below files



app/code/Vendor/Module/etc/events.xml



<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="vendor_extension_change_currency_position" instance="VendorModuleModelObserverChangecurrencyposition" />
</event>
</config>


appcodeVendorModuleModelObserverChangecurrencyposition



<?php 
namespace VendorModuleModelObserver;
use MagentoFrameworkEventObserverInterface;
class Changecurrencyposition implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)

$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', MagentoFrameworkCurrency::LEFT);
return $this;




This worked for me to change the position of price symbol.



Now I need to change the price separator from ',' to '.'
I found a solution here



Added the below files to change the price formatter.
app/code/Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoFrameworkLocaleFormat" type="VendorModuleModelFormat" />
</config>


appcodeVendorModuleModelFormat.php



 <?php
namespace venorModuleModel;

use MagentoFrameworkLocaleBundleDataBundle;

class Format extends MagentoFrameworkLocaleFormat

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,
];
return $result;




But it is working only in view page not in listingpage, minicart etc



Can anyone provide a solution for this??










share|improve this question
























  • Share your code for better understand.

    – Chirag Patel
    Jun 10 at 6:54











  • @ChiragPatel I have added the code. Can you please provide a solution?

    – Vindhuja
    Jun 10 at 7:30













1












1








1








I have a website where currency is displayed in the format xx,xx CHF. I want to it to the format CHF xx.xx



I got the solution to position the currency symbol by refering the below link.



https://magecomp.com/blog/change-currency-symbol-position-left-right-magento-2/



Added the below files



app/code/Vendor/Module/etc/events.xml



<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="vendor_extension_change_currency_position" instance="VendorModuleModelObserverChangecurrencyposition" />
</event>
</config>


appcodeVendorModuleModelObserverChangecurrencyposition



<?php 
namespace VendorModuleModelObserver;
use MagentoFrameworkEventObserverInterface;
class Changecurrencyposition implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)

$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', MagentoFrameworkCurrency::LEFT);
return $this;




This worked for me to change the position of price symbol.



Now I need to change the price separator from ',' to '.'
I found a solution here



Added the below files to change the price formatter.
app/code/Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoFrameworkLocaleFormat" type="VendorModuleModelFormat" />
</config>


appcodeVendorModuleModelFormat.php



 <?php
namespace venorModuleModel;

use MagentoFrameworkLocaleBundleDataBundle;

class Format extends MagentoFrameworkLocaleFormat

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,
];
return $result;




But it is working only in view page not in listingpage, minicart etc



Can anyone provide a solution for this??










share|improve this question
















I have a website where currency is displayed in the format xx,xx CHF. I want to it to the format CHF xx.xx



I got the solution to position the currency symbol by refering the below link.



https://magecomp.com/blog/change-currency-symbol-position-left-right-magento-2/



Added the below files



app/code/Vendor/Module/etc/events.xml



<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="vendor_extension_change_currency_position" instance="VendorModuleModelObserverChangecurrencyposition" />
</event>
</config>


appcodeVendorModuleModelObserverChangecurrencyposition



<?php 
namespace VendorModuleModelObserver;
use MagentoFrameworkEventObserverInterface;
class Changecurrencyposition implements ObserverInterface

public function execute(MagentoFrameworkEventObserver $observer)

$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', MagentoFrameworkCurrency::LEFT);
return $this;




This worked for me to change the position of price symbol.



Now I need to change the price separator from ',' to '.'
I found a solution here



Added the below files to change the price formatter.
app/code/Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoFrameworkLocaleFormat" type="VendorModuleModelFormat" />
</config>


appcodeVendorModuleModelFormat.php



 <?php
namespace venorModuleModel;

use MagentoFrameworkLocaleBundleDataBundle;

class Format extends MagentoFrameworkLocaleFormat

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,
];
return $result;




But it is working only in view page not in listingpage, minicart etc



Can anyone provide a solution for this??







magento2 price format






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 10 at 7:33







Vindhuja

















asked Jun 10 at 6:21









VindhujaVindhuja

695524




695524












  • Share your code for better understand.

    – Chirag Patel
    Jun 10 at 6:54











  • @ChiragPatel I have added the code. Can you please provide a solution?

    – Vindhuja
    Jun 10 at 7:30

















  • Share your code for better understand.

    – Chirag Patel
    Jun 10 at 6:54











  • @ChiragPatel I have added the code. Can you please provide a solution?

    – Vindhuja
    Jun 10 at 7:30
















Share your code for better understand.

– Chirag Patel
Jun 10 at 6:54





Share your code for better understand.

– Chirag Patel
Jun 10 at 6:54













@ChiragPatel I have added the code. Can you please provide a solution?

– Vindhuja
Jun 10 at 7:30





@ChiragPatel I have added the code. Can you please provide a solution?

– Vindhuja
Jun 10 at 7:30










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277763%2fmagento2format-price%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277763%2fmagento2format-price%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

Log in Navigation menu

Invalid response line returned from server: HTTP/2 401 | ErrorPlease Please Help With Error 500 Internal Server Error after upgrading from 1.7 to 1.9Unable to place new customer orders in admin backendMagento - For “Manage Categories” Forbidden You do not have permission to access this documentHTTP ERROR 500 when using require(_once) app/Mage.phpMemcached causing Web Setup Wizard ErrorCould not create an acl object: Invalid XMLAn error occurred on the server. Please try to place the order againInvalid response line returned from server: HTTP/2 200 - message after update to 2.1.7Magento-CE 2.3.0 installation error on XamppMagento 2.2.6- After Migration all default Payment Methods are not working fine