title: Convert double to BigDecimal and set BigDecimal Precision
body: <p>In Java, I want to take a double value and convert it to a <code>BigDecimal</code> and print out its String value to a certain precision.  </p>
  
  <pre><code>import java.math.BigDecimal;
  public class Main {
      public static void main(String[] args) {
          double d=-.00012;
          System.out.println(d+""); //This prints -1.2E-4
  
          double c=47.48000;
          BigDecimal b = new BigDecimal(c);
          System.out.println(b.toString()); 
          //This prints 47.47999999999999687361196265555918216705322265625 
      }
  }
  </code></pre>
  
  <p>It prints this huge thing:</p>
  
  <blockquote>
    <p>47.47999999999999687361196265555918216705322265625</p>
  </blockquote>
  
  <p>and not</p>
  
  <blockquote>
    <p>47.48</p>
  </blockquote>
  
  <p>The reason I'm doing the <code>BigDecimal</code> conversion is sometimes the double value will contain a lot of decimal places (i.e. <code>-.000012</code>) and the when converting the double to a String will produce scientific notation <code>-1.2E-4</code>.  I want to store the String value in non-scientific notation. </p>
  
  <p>I want to have BigDecimal always have two units of precision like this: "47.48".  Can BigDecimal restrict precision on conversion to string?</p>