每当我们需要高十进制精度时,我们使用小数来进行计算。有没有办法检查精度是否足够进行计算?
我想让以下代码抛出异常:
decimal almostMax = Decimal.MaxValue - 1;
decimal x = almostMax + 0.1m; // This should create an exception, since x equals almostMax.
Assert.AreEqual(x, almostMax); // This does NOT fail.
在实际代码中并不是非常重要,但保持安全性还是很好的。