Suppose I have a decimal value in Java that represents money.
What's the best way to round these values?
For example, if I have a value that's calculated based on a tax rate and I end up with a result of, say, 5.3999999999999995
as the tax amount, should I round it to 2 decimal places simply by doing this:
double d = 5.3999999999999995
BigDecimal bd = new BigDecimal(d).setScale(2, RoundingMode.HALF_EVEN);
d = bd.doubleValue();
to produce the currency value:
5.40