Magento 2中使用JavaScript格式化价格

在javascript中,我已经计算了一个数字。我要显示为价格。

我的JS文件

define([
    'jquery'
], function ($) {
    "use strict";

    function irreleventCalculations() {
        // black magic here
        return 19.949999;
    }
    var price = irrelevenCalculation();

    jQuery('#myCustomPriceDiv').text(formatedPrice);

    return $;
});

我应该如何在Magento 2中执行此操作?

回答:

看看shipping_method / price.js

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());
            }
        });
    }
);

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论