title: Printing increments of 0.1 in c#
body: <p>Im currently reading Code Complete by Steve McConnell, specifically page 295 on floating-point numbers.</p>
  
  <p>When i ran the following code:</p>
  
  <pre><code>        double nominal = 1.0;
          double sum = 0.0;
  
          for (int i = 0; i &lt; 10; i++)
          {
              sum += 0.1;
              Console.WriteLine("sum: " + sum.ToString());
          }
  
          if (equals(nominal,sum))
          {
              Console.WriteLine("Numbers are the same");
          }
          else
          {
              Console.WriteLine("Numbers are different");
          }
  </code></pre>
  
  <p>I got a print out of
  <em>0.1
  0.2
  0.3
  0.4
  0.5
  0.6
  0.7
  0.8
  0.9
  1.0
  Numbers are different</em></p>
  
  <p>How come I didn't get the output that is suppose to happen?
  ie:
  <em>0.1
  0.2
  0.30000000000000004
  0.4
  0.5
  0.6
  0.7
  0.79999999999999999
  0.89999999999999999
  0.99999999999999999
  Numbers are different</em></p>
  
  <p>Is C# rounding numbers when I do an implicit conversion from double to string? I think so because when i debug the application and step through the for loop, i can see the non-terminating repeating decimal numbers. What do you think? Am i right or wrong?</p>