title: Need Idempotence on rounding operation
body: <p>In Java, I would like 0.101d, 0.109999999d, and 0.11000d to all be functionally equivalent. I have attempted to use BigDecimal and a MathContext with 2 digits of precision and RoundingMode.CEILING to do this, but my unit test shows that 0.11000 rounds to 0.12. I want 0.110000d to Round to 0.11. </p>
  
  <pre><code>    private static MathContext targetMathContext = new MathContext(2, RoundingMode.CEILING);
  
  public static double roundedTarget(double d) {
      BigDecimal bd = new BigDecimal(d,targetMathContext);
      return bd.doubleValue();
  }
  </code></pre>
  
  <p>JUnit: </p>
  
  <pre><code>    double c = 0.445d;
      double s = 0.5d;
      double p = (s-c)/s; // 0.1099999..... in dfp
      double rgpp = roundedTarget(p); // 0.11
      double rgppp = roundedTarget(rgpp); // 0.12
      // operation is not idempotent as f(x) != f(f(x))   :(
  
      Assert.assertEquals("These values should be equal",rgpp,rgppp);
  </code></pre>
  
  <p>Solution:</p>
  
  <pre><code>    public static double roundedTarget(double d) {
          return  BigDecimal.valueOf(d)
                    .setScale(2,BigDecimal.ROUND_CEILING)
                    .doubleValue();
      }
  </code></pre>