title: C# Float expression: strange behavior when casting the result float to int
body: <p>I have the following simple code : </p>
  
  <pre><code>int speed1 = (int)(6.2f * 10);
  float tmp = 6.2f * 10;
  int speed2 = (int)tmp;
  </code></pre>
  
  <p><code>speed1</code> and <code>speed2</code> should have the same value, but in fact, I have :</p>
  
  <pre><code>speed1 = 61
  speed2 = 62
  </code></pre>
  
  <p>I know I should probably use Math.Round instead of casting, but I'd like to understand why the values are different.</p>
  
  <p>I looked at the generated bytecode, but except a store and a load, the opcodes are the same.</p>
  
  <p>I also tried the same code in java, and I correctly obtain 62 and 62.</p>
  
  <p>Can someone explain this ?</p>
  
  <p><strong>Edit :</strong> 
  In the real code, it's not directly 6.2f * 10 but a function call * a constant. I have the following bytecode :</p>
  
  <p>for <code>speed1</code> : </p>
  
  <pre><code>IL_01b3:  ldloc.s    V_8
  IL_01b5:  callvirt   instance float32 myPackage.MyClass::getSpeed()
  IL_01ba:  ldc.r4     10.
  IL_01bf:  mul
  IL_01c0:  conv.i4
  IL_01c1:  stloc.s    V_9
  </code></pre>
  
  <p>for <code>speed2</code> : </p>
  
  <pre><code>IL_01c3:  ldloc.s    V_8
  IL_01c5:  callvirt   instance float32 myPackage.MyClass::getSpeed()
  IL_01ca:  ldc.r4     10.
  IL_01cf:  mul
  IL_01d0:  stloc.s    V_10
  IL_01d2:  ldloc.s    V_10
  IL_01d4:  conv.i4
  IL_01d5:  stloc.s    V_11
  </code></pre>
  
  <p>we can see that operands are floats and that the only difference is the <code>stloc/ldloc</code>.</p>
  
  <p>As for the virtual machine, I tried with Mono/Win7, Mono/MacOS, and .NET/Windows, with the same results.</p>