title: Javascript math imprecision error? (0.1+0.01+0.01+0.01+0.01+0.01 == 0.15000000000000002)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/588004/is-javascripts-math-broken">Is JavaScript&#39;s Math broken?</a><br>
    <a href="https://stackoverflow.com/questions/6339606/strange-result-with-floating-point-addition">Strange result with floating point addition</a>  </p>
  </blockquote>
  
  
  
  <p>Some simple JavaScript calculations in Safari 5.0.6  but the same phenomenon in Firefox:</p>
  
  <pre><code>var i=0.1;
  i=i+0.01;       //= 0.11
  i=i+0.01;       //= 0.12
  i=i+0.01;       //= 0.13
  i=i+0.01;       //= 0.14
  i=i+0.01;       // expected == 0.15
  console.log(i); // == 0.15000000000000002
  </code></pre>
  
  <p><strong>Where does this imprecision come from?</strong></p>
  
  <p>Sure, I can handle it with <code>i.toPrecision()</code> or other methods, but does it have to be like that? Is this a floating-point rounding error?</p>
  
  <p>The same happens in this example:</p>
  
  <pre><code>var i=0.14+0.01; //expected == 0.15
  console.log(i);  //== 0.15000000000000002
  </code></pre>
  
  <p><strong>What is happening between 0.14 and 0.15?</strong></p>
  
  <pre><code>var i=0.1400001+0.01; //expected==0.1500001
  console.log(i);       //== 0.1500001 ok!
  </code></pre>
  
  <p>and    </p>
  
  <pre><code>var i=0.14000001+0.01; //expected==0.15000001 !! 
  console.log(i);        //== 0.15000001000000002
  </code></pre>
  
  <p>What do I have to do differently to get the correct results?</p>