title: C# float precision
body: <p>Can anyone please explain to me what's happening here:</p>
  
  <pre><code>using System;
  using System.Text;
  
  namespace ConsoleApplication1 {
  
      class Program {
  
          static void Main(string[] args) {
  
              object o = 1000000.123f;
              float f= Convert.ToSingle(o);
              double d = Convert.ToDouble(f);
  
              Console.WriteLine(f.ToString("r"));
              Console.WriteLine(d.ToString("r"));
  
              Console.ReadLine();
  
          }
      }
  }
  </code></pre>
  
  <p>Which outputs:</p>
  
  <p>1000000.13</p>
  
  <p>1000000.125</p>
  
  <p>I expected:</p>
  
  <p>The object o to have an underlying float type (seems to happen [from observing the watch window where it is typed as object {float})</p>
  
  <p>That 1000000.123f would get stored in f as 1000000.125 (The IEEE754 approximation in 32 bits?)</p>
  
  <p>That the double would store 1000000.125 as well (seems to happen even though f doesn't seem to contain what I expected)</p>
  
  <p>That asking for a round trip format on the ToString would give me back 1000000.125 in both cases.</p>
  
  <p>Can anyone tell me what I'm doing wrong to get 1000000.13 when stringing out f?</p>