format currency amount from number to decimal as currency code example
Example 1: format currency amount from number to decimal as currency
function formatCurrency(currencySymbol: any, decimalSeparator: any) {
return function (value: any) {
const wholePart = Math.trunc(value / 100);
let fractionalPart = value % 100;
if (fractionalPart < 10) {
fractionalPart = 0 + fractionalPart;
}
return `${currencySymbol}${wholePart}${decimalSeparator}${fractionalPart}`;
};
}
const PriceLabel = formatPrice('£', '.');
console.log(PriceLabel(53296))
Example 2: format currency amount from number to decimal as currency
function formatCurrency(currencySymbol: any, decimalSeparator: any) {
return function (value: any) {
const wholePart = Math.trunc(value / 100);
let fractionalPart = value % 100;
if (fractionalPart < 10) {
fractionalPart = 0 + fractionalPart;
}
return `${currencySymbol}${wholePart}${decimalSeparator}${fractionalPart}`;
};
}
const PriceLabel = formatPrice('£', '.');
console.log(PriceLabel(53296))