title: round BigDecimal to nearest 5 cents
body: <p>I'm trying to figure out how to round a monetary amount upwards to the nearest 5 cents. The following shows my expected results</p>
  
  <pre><code>1.03     =&gt; 1.05
  1.051    =&gt; 1.10
  1.05     =&gt; 1.05
  1.900001 =&gt; 1.10
  </code></pre>
  
  <p>I need the result to be have a precision of 2 (as shown above).</p>
  
  <h2>Update</h2>
  
  <p>Following the advice below, the best I could do is this</p>
  
  <pre><code>    BigDecimal amount = new BigDecimal(990.49)
  
      // To round to the nearest .05, multiply by 20, round to the nearest integer, then divide by 20
     def result =  new BigDecimal(Math.ceil(amount.doubleValue() * 20) / 20)
     result.setScale(2, RoundingMode.HALF_UP)
  </code></pre>
  
  <p>I'm not convinced this is 100% kosher - I'm concerned precision could be lost when converting to and from doubles. However, it's the best I've come up with so far and <em>seems</em> to work.</p>