-
Notifications
You must be signed in to change notification settings - Fork 6
Balance rounding to cents #20
Open
Description
Dealing with rounding in Care is painful, because the way it handles shares and transactions generates layers and layers of rounding for a single balance. This makes it painful eg. to make a user reach balance exactly 0, or even predict what goes on precisely.
I would find the following process more understandable and reliable:
- only keep in database values that are rounded to 2 decimal places. (I don't know of any money that has fractional units that are not cents, ie. 2 decimal places, but this can easily be made a setting in the admin interface if needed). I think that Care already does this?
- when splitting a share between
nparticipants, instead of plainly dividing, use an euclidean division (in terms of cents). The remainderkwill be< n, randomly and uniformly pickkparticipants that will pay an extra cent and record them in the share (for future evaluations). The law of large numbers should take care of making this algorithm fair.
If I'm not mistaken, and if (1) is already implemented, (2) should be enough to guarantee that a balance never has more than two decimal places — ie. is an actual money amount.
If you approve of this algorithm, I can implement it in Care and make a PR soon-ish.
Activity
Metadata
Metadata
Assignees
Labels
No labels