Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Deutsche Anzeige-Formate fuer die GUI (Ausbaustufe 5).
|
||
|
||
Bewusst ohne locale-Modul: Container-Locales sind nicht garantiert
|
||
installiert, und die Ausgabe hinge sonst vom Host ab. Reine
|
||
Decimal-Formatierung; die JSON-API bleibt Punkt-Dezimal.
|
||
"""
|
||
from decimal import Decimal, ROUND_HALF_UP
|
||
|
||
DE_LABELS = {
|
||
"monthly": "monatlich",
|
||
"quarterly": "vierteljährlich",
|
||
"yearly": "jährlich",
|
||
"annuity": "Annuität",
|
||
"bullet": "endfällig",
|
||
"percent": "Prozent",
|
||
"absolute": "Absolut",
|
||
"remove": "Entfällt",
|
||
"ende": "Ende",
|
||
}
|
||
|
||
|
||
def eur(value) -> str:
|
||
"""Decimal("-2474.5") -> "-2.474,50" (ohne Euro-Zeichen, das setzt das Template)."""
|
||
d = Decimal(str(value)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
|
||
s = f"{d:,.2f}" # US-Trenner: "-2,474.50"
|
||
return s.replace(",", "\x00").replace(".", ",").replace("\x00", ".")
|
||
|
||
|
||
def de_label(value: str) -> str:
|
||
return DE_LABELS.get(value, value)
|
||
|
||
|
||
def pct(value) -> str:
|
||
"""Decimal("12.5") -> "12,5 %"; None -> "–" (z. B. keine Einkünfte)."""
|
||
if value is None:
|
||
return "–"
|
||
d = Decimal(str(value)).quantize(Decimal("0.1"), rounding=ROUND_HALF_UP)
|
||
return f"{d}".replace(".", ",") + " %"
|