3 ms·
OK, I read the first bulletpoint and just thought "How did this get upvoted this much, this makes no sense": > Money isn’t always decimal > A common wisdom in
by hn_throwaway_99 6y ago
OK, I read the first bulletpoint and just thought "How did this get upvoted this much, this makes no sense":
> Money isn’t always decimal
> A common wisdom in database design is “never using floating-point numbers for money”. Some recommend using the MONEY datatype, while others tell you to use DECIMAL.
> Both of these are wrong. Sure, yeah, in the US and most of Europe, money is decimal.
> That’s certainly not the case in Japan – you can’t charge 2500.50 JP¥.
The author has a very odd definition of "Decimal". Integers are most certainly decimals. The fact that in Japan you can't charge fractions of a a yen doesn't mean that Decimal isn't actually an excellent choice to represent that currency, because it certainly can represent any yen value you would need. The whole reason you don't want to use float is because it cannot represent certain valid monetary values.
As others have pointed out, storing values as "the smallest division", e.g. pennies for USD, is just wrong, because there are many contexts where you have to represent fractions of a cent <insert Superman 3 joke here>.
- scrollaway 6y agoThere is a larger point here, that 2500.5 JPY is not a valid amount to charge, thus having it be possible is a problem. Whereas 10000 USD cents is a valid value. Integer storage of money is my favourite as well to be honest. It's easy to work with and reason about, and it just makes decimalization a display issue.
- hn_throwaway_99 6y agoBut as others have pointed out, actual value can be fractional, it's just not priced that way. I mean, in the US it's actually pretty standard for accounting applications to use a scale of 4 (4 units to the right of the decimal point, the default for MONEY), even though people are never charged fractions of a cent. Simplest example someone gave is gas station pricing, in which prices often end in 9/10ths of a cent - the price is calculated that way, and only rounded when the customer pays.
- numpad0 6y agoIsn't the "all prices are pennies" approach the way USD is handled in practice, like "$399.99"? Certainly no one does irrational divisions like "$24 1/3rd". There might be a small paradigm shift that USD or EUR users might feel if they are used to think of supplementary units genuinely as divisions of full units, but I think most systems do consider the main unit as a sum of smallest denomination and not the or any other ways around.