by projectileboy · 8y ago · 0 comments
Not sure what the back office did, but I doubt it was all done in arbitrary position arithmetic.
Note that if an accountant says things need to be accurate down to the penny, that's probably an exaggeration [1]. Financial statements are typically rounded to the thousands, e.g. Intel's are rounded to million [2].
The IRS also lets you round off dollars [3].
I agree though that if you're building a large complex system with many coders, and either 1) nobody has a full view of the calculation and can do the numerical analysis or 2) there's a high chance that at some point in the future you need penny-accurate bookkeeping, then it's safer to use a very wide int or float type.
Of course, there's also the case where the accountant or auditor doesn't actually need penny precision, but it's easier to just tell the coder 'just in case'.
[1] https://www.accountingtools.com/articles/2017/5/14/the-mater...
[2] https://s21.q4cdn.com/600692695/files/doc_financials/2017/an...
[3] https://taxmap.irs.gov/taxmap/pub17/p17-006.htm#TXMP5d034bfb
At a minimum, you look like a rinky dink operation that doesn't know how to add dollars and cents. On the other end of the spectrum, some people will likely accuse you of theft, and not nicely.
Do not fall under the assumption that the amount you mis-bill will inform how upset the people are that contact you. You will likely be the easy and obvious scapegoat for all their recent annoyances. For example, imagine all the people upset at their AT&T, Comcast or Verizon bill, who now have an easy and obvious thing to point at as an example of over billing. Have fun with those transferred emotions...
Note that the article's advice is to use their own library, but the library just uses JS floats as ints and a separate precision arg:
https://github.com/sarahdayan/dinero.js/blob/master/src/dine...
This doesn't give you any more precision than using floats directly, just a wider 'mantissa' range.
I think this analysis misses a deep and important point. The library you linked uses decimal floating point (in software) instead of the binary floating point used by IEEE floats.
The point of this is not to increase overall precision. A double is already precise to 2e-14% of its value, which means it's capable of representing something like $1 Trillion before it will get off by a whole cent.
The point of using decimal floating point is that it can exactly represent the values we care about when dealing with currency. This allows us to have no error, instead of trying to keep our error small. It means we never have to round (unless performing division).
You could have 1000x the precision in binary floating point, and decimal floating point would still be better for money.
> This doesn't give you any more precision than using floats directly, just a wider 'mantissa' range.
Floating point errors sometimes result in slightly smaller values than expected, and this can result in problems when they are passed around if even one spot if missed that needs to round. For example, some databases might truncate 1.9999999999 to 1.99 instead of round to 2.00.
As a simple illustration, consider the following Javascript (because it's easily available):
price1 = 0.10;
price2 = 0.20;
package1 = price1 + price2; // Hmm, 0.30000000000000004 on my system
ten_packages = 10*package1
money_received = 5.00;
change_due = money_received - ten_packages;
// change_due is 1.9999999999999996,should be 2.00
So, either you choose floating point, and make sure to always round prior to display or passing to any other system and if you miss a spot it will probably just work fine until you hit specific values, or you convert to cents, and you only have to worry about overflow, and any place you don't convert is obvious because it's not formatted with cents and is an order of magnitude too large. And if you're worried that an int is too small and might overflow, just use a long, and that problem goes away for all conceivable real values in your lifetime.If you're coding defensively (and we're talking about money here, so why wouldn't you be?), one of them is obviously a better choice
For my software I started using decimaljs for the highest precision but in the end it never made any difference cent wise even when the payments go in the millions.
Some background: funds can handle fractional quotes and each fund can have its own rounding rules, funds mixes can handle fractional percentages, when money enters or leaves the system it gets rounded to cents because you can't move fraction of cents (unless digital)
So, you get issues even using arbitrary precision math.
Operation order matters. Rounding impacts everywhere so you need to be consistent across the business logic, reversing an operation need to have rounding applied in a specific order to result in the final date to match the initial.
Order is also important when splitting money, because the last share gets all the leftover cents that come from rounding the previous shares split so that the total gets allocated fully. I.e. moving the last 1$ from one fund mix to another mix that has 3 equally divided fund is going to round as .33 movement toward each, but you can't just leave that cent on the previous fund mix and you can't just drop it going nobody notices, so one of them gets .34
maybe this is not a technical issue, maybe its a subculture interaction issue that involves a lot of technical details.
i dont think its easy to 'understand' unless one group spends time with another, and i dont mean half an hour meeting, i mean like, shadowing someone for a week.