Code snippets for Manipulating Objects, Arrays, Time, Currency in Javascript
export const convertToCurrency = (
num: number,
{
locale = "en-US",
currency = "THB",
addPrefix = false,
decimal = 2,
includeCent = true
}
) => {
const formatter = new Intl.NumberFormat(locale, {
style: "currency",
currency,
minimumFractionDigits: decimal
});
num = includeCent ? num / 100 : num;
const formatted = formatter.format(num);
return addPrefix ? formatted : formatted.slice(currency.length + 1);
};