Format all monetary amounts as 1'000-separated integers and round amount inputs to nearest 1'000
Deploy App / deploy (push) Successful in 43s

This commit is contained in:
2026-07-08 20:31:34 +02:00
parent a1e689167c
commit 3b68ff8319
7 changed files with 110 additions and 43 deletions
+23
View File
@@ -0,0 +1,23 @@
// Einheitliches Format fuer Geldbetraege im ganzen Tool: Tausendertrennzeichen mit
// geradem Apostroph, keine Nachkommastellen (z. B. 1'780'000). Bewusst nicht ueber
// Intl/toLocaleString("de-CH"), da dessen Gruppentrennzeichen ( U+2019) nicht dem
// geraden Apostroph entspricht.
export function formatChf(value: number): string {
const rounded = Math.round(value || 0);
const sign = rounded < 0 ? "-" : "";
const digits = Math.abs(rounded).toString();
const withSeparators = digits.replace(/\B(?=(\d{3})+(?!\d))/g, "'");
return sign + withSeparators;
}
// Rundet auf ein Vielfaches von 1'000 -- Betraege unter 1'000 CHF sind fuer dieses
// Planungstool nicht relevant.
export function roundToThousand(value: number): number {
return Math.round((value || 0) / 1000) * 1000;
}
export function parseChfInput(text: string): number {
const cleaned = text.replace(/[^0-9-]/g, "");
const parsed = parseInt(cleaned, 10);
return Number.isFinite(parsed) ? parsed : 0;
}