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
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:
@@ -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+$/, '');
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user