Hacker News new | ask | show | jobs
by GuB-42 853 days ago
I heard that countless times, and I understand the reason (mainly: floats are binary, money amounts are decimal), but then, how do you split a $10 bill between 3 people.

$3.33 for each is not good, because in the end you have to pay $10, not $9.99. You can use a double, which is more precise, but in a less predictable way. You can use factions, which is exact, but it may become unmanageable after some time. Or you can have one of the three pay $3.34, but which one? I guess there are rules for that, probably a lot more complicated than "use an integer number of cents".

1 comments

Accountants avoid academic penny drama.

If you have a few grown-up adult parties, e.g. cofounders, partners, then split like [(n-1) x round(total/n), whats_left]. The last one is how sql select sees it.

If you have potentially penny-hysterical kinds (taxes, anonymous group customers), round in their favor and throw pennies into your own expenses.

If n ~~ total, e.g. $100.00 over 700 people, don’t do that, it’s bad accounting.

I worked with finance and accounting half my life. They just don’t fall into these philosophical dilemmas.