title: Round with floor problem in Objective-C
body: <p>I am calculating g with e and s, which are all doubles. After that I want to cut off all digits after the second and save the result in x, for example:</p>
  
  <p>g = 2.123 => x = 2.12</p>
  
  <p>g = 5.34995 => x = 5.34</p>
  
  <p>and so on. I Use...</p>
  
  <pre><code>g = 0.5*e + 0.5*s;
  x = floor(g*100)/100;
  </code></pre>
  
  <p>...and it works fine most of the time. But sometimes I get strange results. For example:</p>
  
  <p>e = 3.0
  s = 1.6
  g = 2.30
  but x = 2.29!!!</p>
  
  <p>So I tried to track down the error:</p>
  
  <pre><code>g = 0.5*e + 0.5*s;
  NSLog(@"%f",g);
  </code></pre>
  
  <p>gives me g = 2.30</p>
  
  <pre><code>g = g * 100;
  NSLog(@"%f",g);
  </code></pre>
  
  <p>gives me g = 230.0</p>
  
  <pre><code>x = floor(g);
  NSLog(@"%f",x);
  </code></pre>
  
  <p>results in x = 229.0 !!! </p>
  
  <p>I don't get it! Help please! :-)</p>