Re:Ask HN: How to handle financial calculations precisely?
by o_nate on Wednesday January 25, 2023 @05:04PM
(#34524793)
So you need 10 digits to the left of the decimal and 2 to the right, for 12 total. A Double should be fine.
[ Parent
| on HN ]
Re:Ask HN: How to handle financial calculations precisely?
by alimw on Wednesday January 25, 2023 @06:19PM
(#34525579)
This seems about right. Work with pennies why not. My very basic test suggests that 1 - 2^(-53) is distinct from 1 in double-land. So if x is the total number of pennies and 2^(-53) * x < 0.5 I can't see why any problem would arise. That's assuming a proper rounding back to integers at the end.