I’m sure there’s an answer to this question buried somewhere on Stack Overflow, but all the ones I could find boil down to either “use the decimal
type” or “convert the money into its lowest denomination (e.g. cents) and store that as an integer”. No one suggested using fractions (i.e. storing the dividend and the divisor).
Fractions can represent numbers that decimals and integers can’t, such as 1/3. Yes, there’s no such thing as 1/3 dollars, but a valid amount, like 1 dollar, could be constructed from the operation 1/3*3. A decimal would give you 0.(9).
In software that deals with arithmetic operations on money—for example, in the domain of accounting—fractions seem a no-brainer. Yet, I couldn’t find anyone recommending this approach. Are there drawbacks I’m not seeing?