From eeb8bfef1597b76d6cfe52b372fe55d30cdd8776 Mon Sep 17 00:00:00 2001 From: krokosik Date: Sun, 16 Aug 2026 18:00:09 +0200 Subject: [PATCH] fix: preserve cents in equal splits --- src/store/addStore.ts | 5 ++++- src/tests/addStore.test.ts | 1 + src/tests/number.test.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/store/addStore.ts b/src/store/addStore.ts index 1ba4f41b1..0dbf1d40b 100644 --- a/src/store/addStore.ts +++ b/src/store/addStore.ts @@ -348,7 +348,10 @@ export function calculateParticipantSplit( if (canSplitScreenClosed) { let penniesLeft = updatedParticipants.reduce((acc, p) => acc + (p.amount ?? 0n), 0n); - const participantsToPick = updatedParticipants.filter((p) => p.amount); + const participantsToPick = + splitType === SplitType.EQUAL + ? updatedParticipants.filter((p) => p.id !== paidBy?.id && 0n !== getSplitShare(p)) + : updatedParticipants.filter((p) => p.amount); const seed = cyrb128( `${participantsToPick diff --git a/src/tests/addStore.test.ts b/src/tests/addStore.test.ts index ffc82790c..026f654d0 100644 --- a/src/tests/addStore.test.ts +++ b/src/tests/addStore.test.ts @@ -590,6 +590,7 @@ describe('calculateParticipantSplit', () => { const totalAmount = result.participants.reduce((sum, p) => sum + (p.amount ?? 0n), 0n); expect(totalAmount).toBe(0n); + expect(result.participants.some((p) => -1n === p.amount)).toBe(true); }); }); }); diff --git a/src/tests/number.test.ts b/src/tests/number.test.ts index 0cec4f20f..15c14456a 100644 --- a/src/tests/number.test.ts +++ b/src/tests/number.test.ts @@ -70,6 +70,18 @@ describe('getCurrencyHelpers', () => { expect(toUIString(value)).toBe(expected); }); }); + + describe('NZD', () => { + const { toSafeBigInt, toUIString } = getCurrencyHelpers({ + locale: 'en-NZ', + currency: 'NZD', + }); + + it('preserves one cent when parsing and displaying an amount', () => { + expect(toSafeBigInt('0.01')).toBe(1n); + expect(toUIString(1n, false, true)).toBe('0.01'); + }); + }); }); describe('bg-BG locale', () => {