From 14cf1b1d356a4a00b07f087e53c541b4dfe049fd Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Wed, 22 Apr 2026 16:55:29 +0200 Subject: [PATCH] feat(format): formatQuantity app-weit auf de-DE Komma-Dezimal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ersetzt Math.round/toFixed-Logik durch q.toLocaleString('de-DE', …). Dezimaltrennzeichen ist jetzt konsistent ein Komma (0,5 statt 0.5). Tests aktualisiert; alle 316 Tests + svelte-check grün. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/quantity-format.ts | 8 ++++---- tests/unit/quantity-format.test.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/quantity-format.ts b/src/lib/quantity-format.ts index 6346dab..653ed6f 100644 --- a/src/lib/quantity-format.ts +++ b/src/lib/quantity-format.ts @@ -1,7 +1,7 @@ export function formatQuantity(q: number | null): string { if (q === null || q === undefined) return ''; - const rounded = Math.round(q); - if (Math.abs(q - rounded) < 0.01) return String(rounded); - // auf max. 2 Nachkommastellen, trailing Nullen raus - return q.toFixed(2).replace(/\.?0+$/, ''); + return q.toLocaleString('de-DE', { + maximumFractionDigits: 2, + useGrouping: false + }); } diff --git a/tests/unit/quantity-format.test.ts b/tests/unit/quantity-format.test.ts index a631b06..498fc6f 100644 --- a/tests/unit/quantity-format.test.ts +++ b/tests/unit/quantity-format.test.ts @@ -16,10 +16,10 @@ describe('formatQuantity', () => { }); it('renders fractional with up to 2 decimals, trailing zeros trimmed', () => { - expect(formatQuantity(0.5)).toBe('0.5'); - expect(formatQuantity(0.333333)).toBe('0.33'); - expect(formatQuantity(1.1)).toBe('1.1'); - expect(formatQuantity(1.1)).toBe('1.1'); + expect(formatQuantity(0.5)).toBe('0,5'); + expect(formatQuantity(0.333333)).toBe('0,33'); + expect(formatQuantity(1.1)).toBe('1,1'); + expect(formatQuantity(1.1)).toBe('1,1'); }); it('handles zero', () => {