title: java double precision
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/872544/precision-of-floating-point">Precision of Floating Point</a>  </p>
  </blockquote>
  
  
  
  <pre><code>        double a=0.000001,b=50000;
          b=a*b;
          System.out.println("double:"+b); // -&gt; double:0.049999999999999996
  
          float a=0.000001f,b=50000;
          b=a*b;
          System.out.println("float"+b);  // -&gt; float0.05
  </code></pre>
  
  <p>I have used double in most part of my code and today I found this problem.
  How should I handle this?</p>
  
  <p>Context:</p>
  
  <pre><code>        double []refValues= {100,75,50,25,15,5,1};
  
          double bInMilliGram=b*1000;
          double pickedVal=0;
          for(double ref:refValues)
              if(ref&lt;=bInMilliGram) {
                  pickedVal=ref;
                  break;
              }
          System.out.println("bInMilliGram:"+bInMilliGram+", pickedVal:"+pickedVal);
  </code></pre>
  
  <p>o/p: ->  bInMilliGram:49.99999999999999, pickedVal:25.0</p>