I have a method with two values ββentered double
. When I try to add them together, I get the wrong values ββover a specific threshold, so I started using it BigDecimal
.
However, even with BigDecimal
I still have the wrong values?
double value1 = 2789.45;
double value2 = 557.89;
System.out.println(BigDecimal.valueOf(value1 + value2));
prints
3347.3399999999997
when he should read how
3347.34
How can I do it right, even if value1
it value2
can be higher than the current area? (they are calculated by a separate method).
Should rounding be used?
source
share