Format price with javascript in Magento 2
Take a look at 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());
}
});
}
);
Based on the answer of R.S
define([
'jquery',
'Magento_Catalog/js/price-utils'
], function ($, priceUtils) {
"use strict";
function irreleventCalculations() {
// black magic here
return 19.949999;
}
var price = irrelevenCalculation();
price = priceUtils.formatPrice(price);
jQuery('#myCustomPriceDiv').text(formatedPrice);
return $;
});