title: What causes "Non-terminating decimal expansion" exception from BigDecimal.divide?
body: <p>I've used BigDecimals before but not very often and I was working on something this morning and I kept getting the following exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion;
  no exact representable decimal result.
      at java.math.BigDecimal.divide(BigDecimal.java:1594)
  </code></pre>
  
  <p>I was attempting to set the scale and use rounding to eliminate the problem like so:</p>
  
  <pre><code>    BigDecimal bd1 = new BigDecimal(1131).setScale(2,BigDecimal.ROUND_HALF_UP);
      BigDecimal bd2 = new BigDecimal(365).setScale(2,BigDecimal.ROUND_HALF_UP);
      BigDecimal bd3 = bd1.divide(bd2).setScale(2,BigDecimal.ROUND_HALF_UP);
      System.out.println("result: " + bd3);
  </code></pre>
  
  <p>However, I keep getting the same exception. Anyone able to show me where I have made a mistake?</p>