title: Check if BigDecimal is an integer in Java
body: <p>What is an <strong>efficient</strong> way of determining whether a <code>BigDecimal</code> is an integer value in the mathematical sense?</p>
  <p>At present I have the following code:</p>
  <pre><code>private boolean isIntegerValue(BigDecimal bd) {
      boolean ret;
      
      try {
          bd.toBigIntegerExact();
          ret = true;
      } catch (ArithmeticException ex) {
          ret = false;
      }
  
      return ret;
  }
  </code></pre>
  <p>... but would like to avoid the object creation overhead if possible.</p>
  <p>Previously I was using <code>bd.longValueExact()</code> which would avoid creating an object if the <code>BigDecimal</code> was using its compact representation internally, but obviously would fail if the value was too big to fit into a long.</p>