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