This commit is contained in:
commit
59bb5a38a3
132 files changed
+19435
No files matched your search
@@ -0,0 +1,29 @@
|
||||
/** 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}`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user