Skip to content

Navigation Menu

Sign in
Sign up

Balance rounding to cents #20

Open
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:

  1. 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?
  2. when splitting a share between n participants, instead of plainly dividing, use an euclidean division (in terms of cents). The remainder k will be < n, randomly and uniformly pick k participants 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      AltStyle によって変換されたページ (->オリジナル) /