aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/balances.ts
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-07 11:11:53 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-07 11:11:53 -0500
commit6611e3a187e5398f686449938b7cf1ddbfcb5392 (patch)
tree0fae44f29faf8efa68bcdb113ae1ca003cbd024b /src/lib/balances.ts
parentec981fd237a50dfc547d8c162b22f4e1a691c9fc (diff)
Store amounts as cents
Diffstat (limited to 'src/lib/balances.ts')
-rw-r--r--src/lib/balances.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/balances.ts b/src/lib/balances.ts
index 20a83fb..77f4622 100644
--- a/src/lib/balances.ts
+++ b/src/lib/balances.ts
@@ -42,7 +42,7 @@ export function getBalances(
}
function divide(total: number, count: number, isLast: boolean): number {
- if (!isLast) return Math.floor((total * 100) / count) / 100
+ if (!isLast) return Math.floor(total / count)
return total - divide(total, count, false) * (count - 1)
}
@@ -58,7 +58,7 @@ export function getSuggestedReimbursements(
while (balancesArray.length > 1) {
const first = balancesArray[0]
const last = balancesArray[balancesArray.length - 1]
- const amount = Math.round(first.total * 100 + last.total * 100) / 100
+ const amount = first.total + last.total
if (first.total > -last.total) {
reimbursements.push({
from: last.participantId,
@@ -77,5 +77,5 @@ export function getSuggestedReimbursements(
balancesArray.shift()
}
}
- return reimbursements
+ return reimbursements.filter(({ amount }) => amount !== 0)
}