Can anyone please explain to me what's happening here:
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();
}
}
}
Which outputs:
1000000.13
1000000.125
I expected:
The object o to have an underlying float type (seems to happen [from observing the watch window where it is typed as object {float})
That 1000000.123f would get stored in f as 1000000.125 (The IEEE754 approximation in 32 bits?)
That the double would store 1000000.125 as well (seems to happen even though f doesn't seem to contain what I expected)
That asking for a round trip format on the ToString would give me back 1000000.125 in both cases.
Can anyone tell me what I'm doing wrong to get 1000000.13 when stringing out f?