-
Notifications
You must be signed in to change notification settings - Fork 271
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
Fix zero-amount transfers and other rounding issues #164
Conversation
@@ -61,9 +61,9 @@ def get_transactions_to_settle_bill(self): | |||
credits, debts, transactions = [],[],[] | |||
# Create lists of credits and debts | |||
for person in self.members: | |||
if balance[person.id] > 0: | |||
if round(balance[person.id], 2) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be better to do the rounding in the balance()
function instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was also thinking, but I decided against it since balance()
seems to be used in a lot of other places. Some calling functions may need the full floating-point precision to work.
It's a bit like unicode vs. bytestrings: always use unicode internally, and only decode/encode to UTF-8 bytestrings when handling inputs/ouputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looks good to me.
Thanks a lot, welcome here :-) 👍 (tested & reviewed), although I don't know how to trigger the problematic cases, so my test is barely "it does not breaks the existing". Should be easy to provide a test, if you have time, at least for 72f177a ? |
This workarounds a rounding issue caused by the (incorrect) usage of floats for bill amounts. This fixes spiral-project#138
A user with a "0.00" balance would have either a "+0.00" in green or a "-0.00" in red, depending on the exact value of the floating-point value. Fix this by simply rounding to 2 digits before comparing to zero.
3c4c6e4
to
d6cf890
Compare
@JocelynDelalande good idea :) I have added a test for the zero-transfer issue, this is the output before applying b507a5a :
|
Thanks :) |
Fix zero-amount transfers and other rounding issues
These are workarounds for rounding issues.