How to iterate between 0.1f and 1.0f with 0.1f increments in Java?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5257166/java-floats-and-doubles-how-to-avoid-that-0-0-0-1-0-1-0-9000001">Java floats and doubles, how to avoid that 0.0 + 0.1 + … + 0.1 == 0.9000001?</a>  </p>
</blockquote>



<p>I am having a following problem in Java - I need to iterate between 0.1f and 1.0f in 0.1f increments,so I would like my output to look like this:</p>

<pre><code>    0.1
    0.2
    0.3
    0.4
    ...
    0.9
</code></pre>

<p>Instead,when I do:</p>

<pre><code>for(float i = 0.1f; i &lt; 1f; i += 0.1f)
    System.out.println(i);
</code></pre>

<p>I get</p>

<pre><code>0.1
0.2
0.3
0.4
0.5
0.6
0.70000005
0.8000001
0.9000001
</code></pre>

<p>I imagine it has something to do with the way fractions are represented by a computer,but I would like to know why is this,and if there is anything I can do to stop it.
thanks.</p>
