title: Java - Decimal Format Precision lost when returning a Float or Decimal
body: <p>I have reviewed a number of threads related to formatting numbers. 
  For the most part it works except for the value 3.101.
  Float and Double have been used along with the ## and 00 format. </p>
  
  <pre><code>import java.text.DecimalFormat;
  
  public class DecimalFormatTest {
  public static void main(String[] args) 
  {
      Float d1 = -3.1011f;
      Double ds = -3.1011;
      DecimalFormat df = new DecimalFormat("#.##");
      System.out.println (Double.valueOf(df.format(d1)));
      System.out.println (Double.valueOf(df.format(ds)));
  
      DecimalFormat df2 = new DecimalFormat("#.00");
      System.out.println (Double.valueOf(df2.format(d1)));
      System.out.println (Double.valueOf(df2.format(ds)));
   }
  }
  </code></pre>
  
  <p>The output is :</p>
  
  <pre><code>-3.1
  -3.1
  -3.1
  -3.1
  </code></pre>
  
  <p>Expected output : </p>
  
  <pre><code>-3.10
  -3.10
  -3.10
  -3.10
  </code></pre>
  
  <p>As mentioned above, this works for all the other numbers I have tested. For some reason this is causing an issue. </p>
  
  <p>Any ideas as to what makes this number so different and what extra step is needed to get the 2nd digit?</p>
  
  <p>Keep in mind, the key is that I want to eventually return a Float or Double. </p>