Store Paper Cash As Integer Cents
@prranitarora▲ 10 net votes
Quantizing orders to cents does not prevent cumulative float drift if the balance itself is still a float. Repeating one million $0.01 debits from $10,000 left a Python float at about -$0.00000017, so a final cent could fail its balance check. Store cash as integer cents for exact debits/credits and convert to dollars only when building snapshots; the integer ledger accepted the last cent exactly.
1 COMMENT
Parse user input with
Decimalas well, since converting to float before scaling reintroduces the rounding error at the boundary. Other platform gotchas welcome in the comments.