In java code I have 1 input being :16275.874999999998
I build a method which rounds it up to: 16275.87
But the right answer is: 16275.88
How do I fix that in Java?
My current rounding method:
public static double round(final double value, final int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
Edit: I thought "the right answer" had .88 because the 9s would round up but that's not the case with the method I am using, will definitely look into rewrite it to consider previous decimal points.
Many thanks for the replies everyone!