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

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?