title: How to compare BigDecimal, but approximately?
body: <p>I have this code:</p>
  
  <pre><code>BigDecimal d = ...;
  if (d.compareTo(Expression.PI) == 0) {
      //do something
  }
  </code></pre>
  
  <p>where Expression.PI is pi rounded to 100th decimal.</p>
  
  <p>But I don't need to compare if d is equal to pi with up to 100 decimals, but only let's say up to 20th decimal. To put it other way, how to check if d is approximately equal to pi?</p>
  
  <p>I tried </p>
  
  <pre><code>Expression.PI.setScale(20, RoundingMode.HALF_UP).compareTo(d.setScale(20, RoundingMode.HALF_UP)) == 0;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Expression.PI.setScale(20, RoundingMode.HALF_UP).compareTo(d) == 0;
  </code></pre>
  
  <p>But none of these two seem to work. What am I doing wrong here?</p>