title: BigDecimal Subtraction
body: <p>I want to substract 2 <code>double</code> values, and I have tried the following code.</p>
  
  <pre><code>double val1 = 2.0;
  double val2 = 1.10;
  
  System.out.println(val1 - val2);
  </code></pre>
  
  <p>and I got the output as,</p>
  
  <pre><code>0.8999999999999999
  </code></pre>
  
  <p>For getting output as <code>0.9</code> I tried with <code>BigDecimal</code> as follows,</p>
  
  <pre><code>BigDecimal val1BD = new BigDecimal(val1);
  BigDecimal val2BD = new BigDecimal(val2);
  
  System.out.println(val1BD.subtract(val2BD));
  </code></pre>
  
  <p>And I got the output as,</p>
  
  <pre><code>0.899999999999999911182158029987476766109466552734375
  </code></pre>
  
  <p>Then I tried with <code>BigDecimal.valueOf()</code> </p>
  
  <pre><code>val1BD = BigDecimal.valueOf(val1);
  val2BD = BigDecimal.valueOf(val2);
  
  System.out.println(val1BD.subtract(val2BD));
  </code></pre>
  
  <p>And finally I got the output as <code>0.9</code>.</p>
  
  <p>My question is what is the difference between case 2 &amp; case 3? </p>
  
  <p>In case 2 why I got the output like that?</p>