Hacker News new | ask | show | jobs
by grishka 1482 days ago
Why would you ever want monetary amounts as fractions or any kind? Why would you want to separate dollars from cents? Just represent them in cents or other smallest units ($15.27 would be 1527), and only make the distinction between dollars and cents for human-readable output. Problem solved. I don't understand what BCD would solve here vs plain binary integers.
3 comments

> Why would you ever want monetary amounts as fractions or any kind?

If you can exchange arbitrary currency (and other commodity) in specified whole units with no other restrictions, then if you need to track prices, the prices need to be tracked as arbitrary rational numbers.

BCD is, of course, inadequate for that, but it's the most general reason for why monetary amounts may need fractions, IMO.

BCD does mean that when the requirements change from “we need to track to the cent” to “we need to track to the mil”, you change one constant as to the minimum allowed precision, and no other code or existing data. Whereas “use integer multiples of the minimum unit” makes that messier. Also, if you have different minimum units in different parts of an enterprise, using BCD makes sharing between them easier.

When currencies are represented as integers you have trouble doing transactions in multiple currencies.

Floating point is out of the question, so division, multiplication, etc was more accurate in BCD than in integers when different currencies were involved.

as soon as interest or taxes are involved, you'll end up with fractions of cents. Or if you want to split an uneven amount between people.