Docker-Images bauen und veroeffentlichen / build-and-push (push) Failing after 1m32s
30 lines
939 B
TypeScript
30 lines
939 B
TypeScript
/** 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}`);
|
||
}
|
||
}
|