title: Decimal to Float conversion issue in C#
body: <p>Can anyone please help me with this problem?</p>
  
  <p>I have in the database a nullable "real" column that Entity Framework represents as "float?"</p>
  
  <p>The system does some calculations in decimal but when assigns the value in this column the precision is lost.</p>
  
  <p>The system is using the next conversion:</p>
  
  <pre><code>dbObject.floatCol = (float) decimalVar;
  </code></pre>
  
  <p>decimalVar is = 123.12341</p>
  
  <p>but dbObject.floatCol is = 123.1234</p>
  
  <p>I been trying to do this convertion in other ways without luck.</p>
  
  <p>NOTES:</p>
  
  <ol>
  <li>In the database I can update the value to 123.12341 without problem.</li>
  <li>I can't alter the database's column</li>
  <li>I'm using Visual Studio 2010 with .NET Framework 4</li>
  </ol>
  
  <p>EDIT:<br>
  If I debug the problem (with the real numbers of my issue) I have:</p>
  
  <pre><code>decimal decimalVar = new decimal(123.13561);
  // decimalVar is 123.13561
  float? floatVar = 0;
  // floatVar is 0
  floatVar = (float)decimalVar;
  // floatVar is 123.135612 &lt;- has appeared a 2 at the end
  
  // with a different decimal number
  decimalVar = new decimal(128.13561); // replaced the 123 for 128
  // decimalVar is 128.13561
  floatVar = (float)decimalVar;
  // floatVar is 128.1356 &lt;- has disappeared the 1 at the end
  </code></pre>
  
  <p>The behavior is really weird<br>
  I need to know if is possible to do a correct conversion<br>
  When I try to print the values to Console or Logfile they are different :s</p>