fix: handle negative-zero and half-cent rounding in formatGermanAmount

This commit is contained in:
Bastian Wagner
2026-08-03 21:12:27 +02:00
parent cab04c5869
commit c6df6a6d38
2 changed files with 25 additions and 1 deletions

View File

@@ -133,4 +133,26 @@ describe('buildCsv', () => {
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\nKeine Buchungen im gewählten Zeitraum',
);
});
it('formats negative-zero as positive zero', () => {
const csv = buildCsv([
{ date: '2026-08-05T00:00:00.000Z', type: 'expense', who: 'Teamkasse', note: 'Test', amount: -0.001, runningTotal: 0 },
]);
expect(csv).toBe(
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\n' +
'2026-08-05;Ausgabe;Teamkasse;Test;0,00;0,00',
);
});
it('rounds half-cent boundaries correctly', () => {
const csv = buildCsv([
{ date: '2026-08-05T00:00:00.000Z', type: 'payment', who: 'Alex Muster', note: 'Test', amount: 1.005, runningTotal: 1.005 },
]);
expect(csv).toBe(
'Datum;Typ;Wer;Notiz;Betrag;Periodensaldo\r\n' +
'2026-08-05;Zahlung;Alex Muster;Test;1,01;1,01',
);
});
});