Details
-
New Feature
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
Currently Average operator has calculations with double, which in general may not be well suited for monetary operations (this can lead to incorrect results).
sums += tuple.doubleValue();
Reason:
"The float and double types are particularly ill-suited for monetary calculations because it is impossible to represent 0.1 (or any other negative power of ten) as a float or double exactly."
Solution:
"Use BigDecimal, int, or long for monetary calculations."
Reference:
Bloch, Joshua (2008-05-08). Effective Java (2nd Edition) (Java Series) (p. 218). Pearson Education. Kindle Edition.