title: Unexpected behavior of double primitive type data
body: <p>I want to understand how the Java <code>double</code> type will store its value in memory in Java.
  When I run the following code I get unexpected output:</p>
  
  <pre><code>public static void main(String[] args)  {
  
      float a = 1.5f;
      float b= 0.5f;
      double c= 1.5;
      double d = 0.5;
  
      float a1 = 1.4f;
      float b1= 0.5f;
      double c1= 1.4;
      double d1 = 0.5;
  
      System.out.println(" a- b is " + (a-b));
      System.out.println(" c- d is " + (c-d));
      System.out.println("a1-b1 is " + (a1-b1));
      System.out.println("c1-d1 is " + (c1-d1));
  </code></pre>
  
  <p>}</p>
  
  <p>Output:</p>
  
  <pre>
   a- b is 1.0
   c- d is 1.0
  a1-b1 is 0.9
  c1-d1 is 0.8999999999999999
  </pre>
  
  <p>Why is <code>c1-d1</code> not equal to <code>0.9</code>?</p>
  
  <p>I also tried other different values but some time it return expected result and some time not.</p>