spiral-project / ihatemoney

A simple shared budget manager web application
https://ihatemoney.org
Other
1.2k stars 268 forks source link

Store bills in rational cents rather than floats #528

Open Natim opened 4 years ago

Natim commented 4 years ago

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 commented 4 years ago

Refs https://github.com/spiral-project/elm-ihatemoney/pull/16

almet commented 4 years ago

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

Natim commented 4 years ago

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 commented 4 years ago

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

almet commented 4 years ago

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

LeoMouyna commented 4 years ago

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 commented 4 years ago

Yes you are exactly right.

rom1dep commented 4 years ago

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