Can anyone help me understand, because the expected value and the actual value have different results in the ToString()
method. When I open the watch for me it is the same value.
Thanks
Code:
[TestMethod]
public void SerializeDecimalWithTwoDecimals()
{
var expected = decimal.Round(1.00M,2);
var actual = decimal.Round(1M,2);
Assert.AreEqual(expected.ToString(), actual.ToString());
}
Don't believe the Watch window, basically. It can play silly games with string representations of values. The two values are equal (expected == actual
will be true), but they're not identical - the trailing zeroes are preserved.
Here, the Round
method isn't actually changing the values at all, so you've effectively got:
var expected = 1.00m;
var actual = 1m;
Assert.AreEqual(expected.ToString(), actual.ToString());
... and 1.00m.ToString()
is "1.00", whereas 1m.ToString()
is "1".
See more on this question at Stackoverflow