title: C# Math.Round and nullable Doubles
body: <p>I have taken on the task of converting a very old classic ASP/VBScript/Access web site to a "current" site.  As you would suspect, most of it has been easier to just do-over, but there is a reporting page which relies on a bunch of calculations that aren't documented so I just have to use his code/formulas but move them to C#. </p>
  
  <p>Just for full disclosure, I imported the Access database to SQL Server with no issues.  I used EntityFramewok PowerTools (Code First) to reverse engineer the new database and create my .edmx file.  I noticed that when EntityFramework created the .edmx for me, it defined fields that are floats in the database as nullable Doubles (Double?) in the C# class...is there any risk of transposing, chopping, or changing the value in any way when converting float to nullable double?</p>
  
  <p>The other spot that I think is suspect is in the rounding.  Obviously the math around rounding hasn't changed, but I wonder if VBScript and C# have any known differences in how they round.</p>
  
  <p>So these lines in VBScript</p>
  
  <pre><code>varA1=oDataRs("boundData")
  varB1i=varA1*3.0689
  varB1=round(varB1i,3)
  </code></pre>
  
  <p>Becomes this is C#</p>
  
  <pre><code>var newVal = Math.Round(boundData.Value * 3.0689,3);
  </code></pre>
  
  <p>I am not converting anything to double or decimal, just working with it as it comes out of the database.  I do have to use .Value though as I otherwise can't multiply a Double? and a Double.</p>
  
  <p>The values are very close, but off by about .036 on a pretty important piece of data, and I can't find any reason why.</p>