Skip to content

Instantly share code, notes, and snippets.

@cagartner
Last active September 27, 2022 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cagartner/870a8b666fba7a0ccb414e83d0195189 to your computer and use it in GitHub Desktop.
Save cagartner/870a8b666fba7a0ccb414e83d0195189 to your computer and use it in GitHub Desktop.
Formating price on JS for Magento 2
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Catalog/js/price-utils'
],
function ($,quote, priceUtils) {
"use strict";
......
formatedPrice = getFormattedPrice(price)
getFormattedPrice: function (price) {
//todo add format data
// var priceFormat = quote.getPriceFormat();
// or create the format by yourself.
var priceFormat = {
decimalSymbol: '.',
groupLength: 3,
groupSymbol: ",",
integerRequired: false,
pattern: "$%s",
precision: 2,
requiredPrecision: 2
};
// you can use the quote.getPriceFormat when possible or
return priceUtils.formatPrice(price, priceFormat);
}
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment