How to Format price with javascript in Magento 2 - Magento source24

 

How to Format price with javascript in Magento 2 - Magento source24

How to Format price with javascript in Magento 2 - Magento source24


In this Blog post im share code with you to How to Format price with javascript in Magento 2. Add this code in your js file 

In this javascript file, I have calculated a number ( like : 19.949999). Which I want to display as a Format  price.


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

                return priceUtils.formatPrice(price, quote.getPriceFormat());

            }

        });

    }

);


try this : 


define(

    [

        'uiComponent',

        'Magento_Checkout/js/model/quote',

        'Magento_Catalog/js/price-utils'

    ],

    function (Component,quote, priceUtils) {

        "use strict";

        return Component.extend({

            defaults: {

                template: 'Magento_Tax/checkout/shipping_method/price'

            },

            isDisplayShippingPriceExclTax: window.checkoutConfig.isDisplayShippingPriceExclTax,

            isDisplayShippingBothPrices: window.checkoutConfig.isDisplayShippingBothPrices,

            isPriceEqual: function(item) {

                return item.price_excl_tax != item.price_incl_tax;

            },

            getFormattedPrice: function (price) {

                //todo add format data

                return priceUtils.formatPrice(price, quote.getPriceFormat());

            }

        });

    }

);

Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post