title: how does java.math.RoundingMode work?
body: <p>I'm having trouble with rounding. Specifically, after reading all the javadoc, I was expecting the following code:</p>
  
  <pre><code>int n = (integer between 0 and 9, included)
  new BigDecimal(n + 0.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
  </code></pre>
  
  <p>to return <code>n + 0.56</code>. Instead, these are the return values for <code>n</code> from <code>0</code> to <code>4</code>:</p>
  
  <pre><code> new BigDecimal(0.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
   0.56
   new BigDecimal(1.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
   1.55
   new BigDecimal(2.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
   2.56
   new BigDecimal(3.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
   3.56
   new BigDecimal(4.555d).setScale(2, RoundingMode.HALF_UP).doubleValue()
   4.55
  </code></pre>
  
  <p>I have also tried to change the rounding mode:</p>
  
  <pre><code>int n = (integer between 0 and 9, included)
  new BigDecimal(n + 0.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
  </code></pre>
  
  <p>expecting <code>n + 0.55</code> as a result for each and every <code>n</code>. Instead, the return values are exactly the same as the previous example:</p>
  
  <pre><code> new BigDecimal(0.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
   0.56
   new BigDecimal(1.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
   1.55
   new BigDecimal(2.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
   2.56
   new BigDecimal(3.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
   3.56
   new BigDecimal(4.555d).setScale(2, RoundingMode.HALF_DOWN).doubleValue()
   4.55
  </code></pre>
  
  <p>Am I missing something?</p>