title: Java Format Specifier for Limiting Trailing Zeros to 1
body: <p>I'm looking for a format specifier to limit the number of trailing zeros after a decimal to just 1, but if they aren't all zeros then truncate to two.</p>
  
  <p>Like so:</p>
  
  <pre><code>127.000000 -&gt; 127.0
  
  0.000000 -&gt; 0.0
  
  123.456 -&gt; 123.45
  </code></pre>
  
  <p>I Have tried taking care of it with logic but it doesn't seem to work.</p>
  
  <p>call my number <code>result</code> and use the following logic:</p>
  
  <pre><code>    if(result - (int)result == 0){
          output = String.format("%.1f\n",result);
      }
      else{
          output = String.format("%.2f\n,result);
      }
  </code></pre>
  
  <p>sometimes this logic works, and sometimes it doesnt. For example</p>
  
  <p><code>(int)result - result == 0</code>  is <code>true</code> for <code>0.000000</code></p>
  
  <p>but <code>false</code> for <code>127.000000</code></p>
  
  <p>Any ideas?</p>