Skip to content

Instantly share code, notes, and snippets.

@hendryfoe
Created November 6, 2022 15:53
Show Gist options
  • Save hendryfoe/9881f04964bbccece7d1636408863fc9 to your computer and use it in GitHub Desktop.
Save hendryfoe/9881f04964bbccece7d1636408863fc9 to your computer and use it in GitHub Desktop.
format currency utility
export function formatCurrency(
value: number,
locales: string | string[] = 'id',
options: Intl.NumberFormatOptions = { style: 'currency', currency: 'IDR', minimumFractionDigits: 0 }
) {
return new Intl.NumberFormat(locales, options).format(value);
}
export function formatCurrencyWithoutPrefix(value: number, locales: string | string[] = 'id') {
return formatCurrency(value, locales, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment