Is one better than other? It depends on what problem you're looking to solve, what optimizations you value, and what kinds of out of band knowledge you think are the most resilient to rely on.Īnd honestly, the deeper you dig into handling currencies you'll start to understand why even things that seem super clear like $1.50 are ambiguous in several ways: Using the smallest whole number possible and knowing your unit is millionths of a some coin when the currency column is set to 92 is a different set of tradeoffs than we have to do a whole migration of the database to support expanding existing rows to 7 places and now all of your currency entries support that level of precision (likely very incorrectly). Maybe next month we're taking in crypto and we need to support 7 decimal places. Excel + Python + Pandas (for example) does some funky things with numbers that you might not notice until it's too late. It's often wise to round numbers going into the database to something sensible, like 4dp, 8dp, even 10dp to avoid things like 0.999999999998 being the in-code representation of 1.0. But that doesn't mean you have to pollute the database. Sure, if you're a developer you're going to have some nasty choices, like having to work with floating point numbers because your crappy language doesn't support exact numeric types. Storing data in a format that isn't human readable leads to mistakes being made, "I didn't realise the number was hundredths of a cent I assumed it was in dollars - oops!".You're honestly not going to notice the performance difference unless you have billions of rows of data and you're performing lots of really complicated calculations.These integer/ bigint solutions sound great on paper, but then they fall down when you need to store fractional units.You typically won't know what's coming down the line, particularly if you work with global currencies, so why limit yourself to a certain number of decimal places, then have to change it later.GAAP is to go to 4dp to avoid rounding errors slipping in when performing calculations and storing partial results before aggregation.money sucks, even the developer who added it admits it doesn't work properly.Personally I would go with numeric without specifying the number of digits before or after the decimal point.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |