Hacker News new | ask | show | jobs
by dotancohen 653 days ago
Floats are fine for speculation. But they should not be used to record actual transactions.

I typically use the smaller unit of a currency to store transaction amounts. E.g., for a US transaction of $10, I would store the integer 1000 because that is 1000 cents.

1 comments

Or just use decimal numbers instead. Decimal libraries abound. Then you can do rounding however your jurisdiction/bank/etc does it too.