Decimal Is Sometimes Wrong
4 points
47 minutes ago
| 2 comments
| jt-hill.com
| HN
benrutter
28 minutes ago
[-]
I enjoyed reading this! It's not always possible but finance data that translates directly into cents/euro-cents/pence/yen/etc is really nice to work with as integers. Obviously as soon as you need to divide that stops being such a solid strategy though. . .
reply
jt-hill
8 minutes ago
[-]
Thanks! And you're right this is true for storage and at the transaction level where nothing smaller than, e.g., a penny is allowed to move or exist in the first place. But when you're working with interest rates and the main calculations involve multiplying by numbers < 1, you still have to figure out rounding.
reply
jt-hill
42 minutes ago
[-]
Author here. I thought was doing what I was supposed to do by using Decimals heavily in my credkit[0] Python library, but I did some testing and discovered it wasn't worth the pain for me. Test code [1] is available for the curious.

The moral of the story is that "best practices" are not a substitute for using your brain.

[0]: https://github.com/jt-hill/credkit

[1]: https://gist.github.com/jt-hill/839e1a6c51d28cbcb8fc69e61431...

reply