But we have heard this a few times, so I think it would be good to make it explicit somewhere that it's done this way, or switch to bignumber. Do you think if all our calculations are done using decimal places, and then numbers are rounded to integer dollars on the final PDFs, that we'll still have errors?
Created an issue based on your feedback. Thank you! https://github.com/ustaxes/UsTaxes/issues/457
if you can find a way to use only integers within that range, you can do it safely in plain JS.
for example, units of integer microdollars (one millionth of a dollar) allows you to deal in amounts up to $9 billion without exceeding the safe integer limit. if you want a larger range than that, you need to make a corresponding reduction in precision (such as using millidollars).
or, switch to a full-blown bignum / arbitrary precision library.
0: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
https://www.taxact.com/support/14396/2017/forms-w-2-or-1099-...
Aww....
"When you are dealing with things that are measured" ... or wild-ass guesses.
And I doubt demographers and actuaries are all using integer arithmetic for projecting technically integer-count human-life outcomes.
Calculating taxes: Be careful and conventional, as you say.
There are various libraries around that can facilitate precise decimal arithmetic in Javascript. A well known one is BigNumber.js (https://mikemcl.github.io/bignumber.js/)
A great quote that I found on StackOverflow regarding this issue and wrote down:
"When you are dealing with things that are measured (speed, distance, weight etc.) rounding is OK as the accuracy of the original measurement is probably less than the accuracy of your calculation, and users accept that the final number is still an estimate even if its a good estimate. When you are dealing with things that are counted (money, people, ICBMs) rounding errors are a disaster. There is always an arithmetically correct answer, and, often the accuracy of this answer is enshrined in regulation, treaties and tax law. Providing a slightly wrong number gets you a free ticket into the Kafkaesque world of auditors, tax collectors and government inspectors; you may never escape with your sanity intact." - James Anderson
[1] https://stackoverflow.com/questions/3730019/why-not-use-doub...
[2] http://blog.plataformatec.com.br/2014/09/floating-point-and-...