feat(format): formatQuantity app-weit auf de-DE Komma-Dezimal
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 2m19s

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 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 16:55:29 +02:00
parent b85f869c09
commit 14cf1b1d35
2 changed files with 8 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
export function formatQuantity(q: number | null): string { export function formatQuantity(q: number | null): string {
if (q === null || q === undefined) return ''; if (q === null || q === undefined) return '';
const rounded = Math.round(q); return q.toLocaleString('de-DE', {
if (Math.abs(q - rounded) < 0.01) return String(rounded); maximumFractionDigits: 2,
// auf max. 2 Nachkommastellen, trailing Nullen raus useGrouping: false
return q.toFixed(2).replace(/\.?0+$/, ''); });
} }

View File

@@ -16,10 +16,10 @@ describe('formatQuantity', () => {
}); });
it('renders fractional with up to 2 decimals, trailing zeros trimmed', () => { it('renders fractional with up to 2 decimals, trailing zeros trimmed', () => {
expect(formatQuantity(0.5)).toBe('0.5'); expect(formatQuantity(0.5)).toBe('0,5');
expect(formatQuantity(0.333333)).toBe('0.33'); expect(formatQuantity(0.333333)).toBe('0,33');
expect(formatQuantity(1.1)).toBe('1.1'); expect(formatQuantity(1.1)).toBe('1,1');
expect(formatQuantity(1.1)).toBe('1.1'); expect(formatQuantity(1.1)).toBe('1,1');
}); });
it('handles zero', () => { it('handles zero', () => {