Hacker News new | ask | show | jobs
by FabHK 34 days ago
But it's a good idea to keep those values distinct from actual money. You can't pay a fraction of a cent to anyone.
2 comments

If you're calculating stock gains, taxes, etc. You'll want to do it on BigDecimal on line items, then sum it up. Cents could lose precision leading to a large difference on millions of line items.

If you're doing static payments or displaying a number, it doesn't matter if it's float amounts or integer cents since you're not doing any calculations anyway.

Stripe uses cents mostly because it's the most foolproof way that won't cause massive issues as a public API.

But the price of some unit of a commodity may well be expressed in smaller fractions to allow for small price changes.

You could argue that a price is not really an amount that anyone can actually pay and that's true. But it seems complex and error prone to store unit prices and amounts using different scaling factors.