ihatemoney icon indicating copy to clipboard operation
ihatemoney copied to clipboard

Store bills in rational cents rather than floats

Open Natim opened this issue 5 years ago • 8 comments

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 avatar Jan 17 '20 08:01 Natim

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

Natim avatar Jan 17 '20 08:01 Natim

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

almet avatar Jan 17 '20 12:01 almet

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 avatar Jan 17 '20 13:01 Natim

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

Natim avatar Jan 17 '20 13:01 Natim

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

almet avatar Jan 17 '20 15:01 almet

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 ?

LeoMouyna avatar Mar 09 '20 10:03 LeoMouyna

Yes you are exactly right.

Natim avatar Mar 09 '20 13:03 Natim

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

rom1dep avatar Apr 15 '20 17:04 rom1dep