Files
Artista-Filmcamp/src/lib/money.ts
T
Nick Szaunig 59bb5a38a3
Docker-Images bauen und veroeffentlichen / build-and-push (push) Failing after 1m32s
first commit
2026-09-27 06:06:56 +02:00

30 lines
939 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Alle Betraege sind ganzzahlige Cent in EUR. */
const eur = new Intl.NumberFormat("de-DE", {
style: "currency",
currency: "EUR",
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
/** 220000 -> "2.200,00 €" */
export function formatEuro(cents: number): string {
assertCents(cents);
// Intl setzt ein geschuetztes Leerzeichen vor das Eurozeichen; fuer
// E-Mails/CSV ist ein normales Leerzeichen robuster.
return eur.format(cents / 100).replace(/ /g, " ");
}
/** 220000 -> "2.200 €" (nur fuer glatte Betraege in Ueberschriften). */
export function formatEuroShort(cents: number): string {
assertCents(cents);
if (cents % 100 !== 0) return formatEuro(cents);
return `${new Intl.NumberFormat("de-DE").format(cents / 100)} €`;
}
export function assertCents(cents: number): void {
if (!Number.isSafeInteger(cents)) {
throw new Error(`Betrag muss ganzzahlige Cent sein, erhalten: ${cents}`);
}
}