我知道是因为这个:
“Because of the loss of precision that can result from representing
decimal values as floating-point numbers or performing arithmetic
operations on floating-point values,in some cases the Round(Double,
Int32,MIDpointRounding) method may not appear to round mIDpoint
values as specifIEd by the mode parameter. This is illustrated in the
following example,where 2.135 is rounded to 2.13 instead of 2.14.
This occurs because internally the method multiplIEs value by 10 *
digits,and the multiplication operation in this case suffers from a
loss of precision.”
但是我应该使用哪种.NET方法来进行正确的舍入?
解决方法 1.7346应该四舍五入到1.73,即使是AwayFromZero
,因为这只会改变“当一个数字介于另外两个之间时”的舍入行为(例如,如果它是1.735). 您可以使用获得所需的行为
Math.Round(Math.Round(1.7346,3,AwayFromZero),AwayFromZero)
(但不要认为这不仅仅是一个黑客).
总结以上是内存溢出为你收集整理的c# – 第1,7346至1,74轮全部内容,希望文章能够帮你解决c# – 第1,7346至1,74轮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)