Files
splitt-the-bill/shared/utils/money.ts
T
anbraten 99a9f908f1
tinyedge/deploy Deployed by TinyEdge
move tabs into own pages
2026-08-07 15:49:43 +02:00

23 lines
528 B
TypeScript

export function toCents(amount: number): number {
return Math.round(amount * 100);
}
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 {
const locale = LOCALE_BY_CURRENCY[currency] ?? 'de-DE';
return new Intl.NumberFormat(locale, {
style: 'currency',
currency,
}).format(fromCents(cents));
}