title: Removing trailing zeros from BigDecimal in Java
body: <p>I need to remove trailing zeros from <code>BigDecimal</code> along with <code>RoundingMode.HALF_UP</code>. For instance,</p>
  
  <pre><code>Value        Output
  
  15.3456  &lt;=&gt; 15.35
  15.999   &lt;=&gt; 16            //No trailing zeros.
  15.99    &lt;=&gt; 15.99
  15.0051  &lt;=&gt; 15.01
  15.0001  &lt;=&gt; 15           //No trailing zeros.
  15.000000&lt;=&gt; 15           //No trailing zeros.
  15.00    &lt;=&gt; 15           //No trailing zeros.
  </code></pre>
  
  <p><a href="https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#stripTrailingZeros--" rel="noreferrer"><code>stripTrailingZeros()</code></a> works but it returns scientific notations in situations like,</p>
  
  <pre><code>new BigDecimal("600.0").setScale(2, RoundingMode.HALF_UP).stripTrailingZeros();
  </code></pre>
  
  <p>In this case, it returns <code>6E+2</code>. I need this in a custom converter in JSF where it might be ugly for end users. So, what is the proper way of doing this?</p>