3 ms·
That fails often because the precision is set to 0. That means, as per BigDecimal javadoc, that results not representable exactly give an exception. That can ha
by fedeb95 4y ago
That fails often because the precision is set to 0. That means, as per BigDecimal javadoc, that results not representable exactly give an exception. That can happen in divisions. You don't want that with money since it always ends up rounded to 2 in the end. The goal is to accumulate as less as possible rounding errors along the way.
- viraptor 4y agoI think there are mainly 2 scenarios for strict rules. Either you deal with actual financial data and there will be laws around how to do the rounding correctly for each case, or you're doing some analytics and you can just agree on what kind of error is acceptable. You can do the analysis of what the error in the result may be and check with the people who use the result. So basically there are either rules around the calculation that you're not aware of yet, or you're doing it for some ad-hoc graphs where the answer is "Yolo, just choose some large number for precision".
- fedeb95 4y agoI'm dealing with actual financial data and I don't think there are laws regarding exactly how you should deal with money in terms of specific algorithms. If you have any pointers...
- viraptor 4y agoTalk to a local accountant. Even if there's no law for your specific situation, there will be one applicable for the country, or at least a known rule everyone follows that's accepted by the local tax org.