title: How to avoid floating point precision errors with floats or doubles in Java?
body: <p>I have a very annoying problem with long sums of floats or doubles in Java. Basically the idea is that if I execute:</p>
  
  <pre><code>for ( float value = 0.0f; value &lt; 1.0f; value += 0.1f )
      System.out.println( value );
  </code></pre>
  
  <p>What I get is:</p>
  
  <pre><code>0.0
  0.1
  0.2
  0.3
  0.4
  0.5
  0.6
  0.70000005
  0.8000001
  0.9000001
  </code></pre>
  
  <p>I understand that there is an accumulation of the floating precision error, however, how to get rid of this? I tried using doubles to half the error, but the result is still the same.</p>
  
  <p>Any ideas?</p>