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

Store bills in rational cents rather than floats #528

Open
Natim opened this issue Jan 17, 2020 · 8 comments
Open

Store bills in rational cents rather than floats #528

Natim opened this issue Jan 17, 2020 · 8 comments

Comments

@Natim
Copy link
Member

Natim commented Jan 17, 2020

Storing bills as floats leads to a number of problematic edge cases.

Instead we should handle money as integers in cents and then display them as float in the end.

We did this change on the elm-ihatemoney project during yesterday hackathon with @gdeest and I think we should fix it in the API as well.

@Natim
Copy link
Member Author

Natim commented Jan 17, 2020

@almet
Copy link
Member

almet commented Jan 17, 2020

I believe this is a duplicate of #165, isn't it?

@Natim
Copy link
Member Author

Natim commented Jan 17, 2020

Yes but #165 was closed while we are still using float. And as you well know, we have a couple more bugs with the external lib too.

@Natim
Copy link
Member Author

Natim commented Jan 17, 2020

More interesting research here: https://ren.zone/articles/safe-money

@almet
Copy link
Member

almet commented Jan 17, 2020

Yes, you're right : we should move away from these silly floats!

@LeoMouyna
Copy link
Contributor

Hey @Natim !
Are you sure you want to store integers ? After reading your article we might want to store it as decimal string: https://docs.python.org/3/library/decimal.html and do operations with fractions: https://docs.python.org/3/library/fractions.html
What do you think about this ?

@Natim
Copy link
Member Author

Natim commented Mar 9, 2020

Yes you are exactly right.

@rom1dep
Copy link

rom1dep commented Apr 15, 2020

@LeoMouyna how do you plan on serializing Fraction('1.1') + Fraction('0.3') + Fraction(100 ,3)? as a (521, 15) tuple?

almet added a commit that referenced this issue Dec 27, 2024
Cases has been reported of rounding issues making deactivated users
reapparing. This is due to the fact we're using floats (see #528 for
details)

Fixes #1336
almet added a commit that referenced this issue Dec 28, 2024
Cases has been reported of rounding issues making deactivated users
reapparing. This is due to the fact we're using floats (see #528 for
details)

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

No branches or pull requests

5 participants