title: How to cast float to double without extra digits added?
body: <p>I came across an interesting problem: when I convert the <code>float</code> value <code>-99.9f</code> to a <code>double</code> variable, that variable's value is <code>-99.9000015258789</code>
  Therefore this unit test fails:</p>
  
  <pre><code>float f = -99.9f;
  double d = (double)f;
  Assert.AreEqual(-99.9, d);
  </code></pre>
  
  <p>I understand that an extra 32 bits are being added in various places. Yet, the value I'm after, <code>-99.9000000000000</code>, is represented just fine as a double if I assign it directly, as evidenced by this unit test:</p>
  
  <pre><code>double d2 = -99.9;
  Assert.AreEqual(-99.9, d2);
  Assert.AreEqual(-99.9000000000000, d2);
  </code></pre>
  
  <p>So my ultimate question is: is it possible to take <code>-99.9f</code> and convert it to a <code>double</code> such that it will truly equal <code>-99.9000000000000</code>?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I found a workaround that, for the moment, seems to work well for my particular application (i.e. one where I don't know ahead of time how many digits of precision to round the float to):</p>
  
  <pre><code>float f = -99.9f;
  double d = double.Parse(f.ToString("r"));
  Assert.AreEqual(-99.9, d);
  </code></pre>
  
  <p>I'm not sure if this would work for all cases; comments are welcome</p>
  
  <p><strong>EDIT 2</strong>
  As per Lasse V. Karlsen`s answer below, the solution was to use the MSTest equivalent to the AreEqual method:</p>
  
  <pre><code>Assert.AreEqual(-99.9, d, 0.00001);
  </code></pre>
  
  <p>Note that if I were to add one more zero to that delta value, the test would fail</p>