Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to ratio_split() #38

Merged
merged 2 commits into from
Apr 21, 2020

Conversation

damiendr
Copy link
Contributor

@damiendr damiendr commented Apr 4, 2019

The current implementation of ratio_split() distributes any change left after rounding to the last participant.

This causes two minor issues:

  • participants with a ratio == 0 may still end up receiving change (debit or credit)
  • the distribution of change is not fair, eg. one participant may end up paying 0.03 more instead of having three participants pay 0.01 more.

This PR fixes this by using the Largest Remainder method to allocate change between participants with a ratio != 0.

It also fixes a further problem whereby ratio_split() assumed DECIMAL_PLACES=2.

@coveralls
Copy link

coveralls commented Apr 4, 2019

Coverage Status

Coverage decreased (-0.05%) to 95.433% when pulling 92423c9 on damiendr:better_ratio_split into 0ffcad1 on adamcharnock:master.

@adamcharnock adamcharnock merged commit ff88f7c into adamcharnock:master Apr 21, 2020
@adamcharnock
Copy link
Owner

Hi @damiendr! Thank you for this, and sorry for taking so long to get back to you. I've merged this now and it should be released soon.

@adamcharnock
Copy link
Owner

Released in 1.10.0, which also drops support for Python 3.5 and includes #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants