@@ -6,8 +6,16 @@ export function fromCents(cents: number): number {
|
||||
return cents / 100;
|
||||
}
|
||||
|
||||
const LOCALE_BY_CURRENCY: Record<string, string> = {
|
||||
EUR: 'de-DE',
|
||||
USD: 'en-US',
|
||||
GBP: 'en-GB',
|
||||
CHF: 'fr-CH',
|
||||
};
|
||||
|
||||
export function formatCurrency(cents: number, currency: string): string {
|
||||
return new Intl.NumberFormat(undefined, {
|
||||
const locale = LOCALE_BY_CURRENCY[currency] ?? 'de-DE';
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
}).format(fromCents(cents));
|
||||
|
||||
Reference in New Issue
Block a user