title: Double precision problems on .NET
body: <p>I have a simple C# function:</p>
  
  <pre><code>public static double Floor(double value, double step)
  {
      return Math.Floor(value / step) * step;
  }
  </code></pre>
  
  <p>That calculates the higher number, lower than or equal to "value", that is multiple of "step". But it lacks precision, as seen in the following tests:</p>
  
  <pre><code>[TestMethod()]
  public void FloorTest()
  {
      int decimals = 6;
      double value = 5F;
      double step = 2F;
      double expected = 4F;
      double actual = Class.Floor(value, step);
      Assert.AreEqual(expected, actual);
      value = -11.5F;
      step = 1.1F;
      expected = -12.1F;
      actual = Class.Floor(value, step);
      Assert.AreEqual(Math.Round(expected, decimals),Math.Round(actual, decimals));
      Assert.AreEqual(expected, actual);
  }
  </code></pre>
  
  <p>The first and second asserts are ok, but the third fails, because the result is only equal until the 6th decimal place. Why is that? Is there any way to correct this?</p>
  
  <p><strong>Update</strong> If I debug the test I see that the values are equal until the 8th decimal place instead of the 6th, maybe because Math.Round introduces some imprecision.</p>
  
  <p><strong>Note</strong> In my test code I wrote the "F" suffix (explicit float constant) where I meant "D" (double), so if I change that I can have more precision.</p>