绕过Math.round(200.925,2) [英] rouding through Math.round(200.925,2)

查看:68
本文介绍了绕过Math.round(200.925,2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我正在使用VS 2005,C#,asp.net.
我正在使用Math.round函数舍入到2个小数点.
Math.round(200.925,2)= 200.92
不舍入到200.93.
但是Math.round(200.935,2)= 200.94
Math.round(200.945,2)= 200.95
不将200.925舍入的原因是什么?

此致
george n

Hi friends,

I am using VS 2005,C#,asp.net.
I am using Math.round function to round to 2 decimal points.
Math.round(200.925,2) =200.92
Not rounding to 200.93.
But Math.round(200.935,2) =200.94
Math.round(200.945,2) =200.95
What is the reason for not rounding of 200.925

Regards,
george n

推荐答案

来自文档
http://msdn.microsoft.com/en-us/library/3s2d3xkk.aspx [ ^ ]

如果 d 的小数部分位于两个整数之间的中间,其中一个为偶数,另一个为奇数,则返回偶数.请注意,此方法返回的是Decimal而不是整数类型

现在,您声明Math.round(200.945,2) = 200.95,根据文档,这将是错误的.在我的系统上Math.round(200.945,2) = 200.94
From the documentation
http://msdn.microsoft.com/en-us/library/3s2d3xkk.aspx[^]

If the fractional component of d is halfway between two integers, one of which is even and the other odd, the even number is returned. Note that this method returns a Decimal instead of an integral type

Now you state that Math.round(200.945,2) = 200.95 which would then be wrong according to the documentation. On my system Math.round(200.945,2) = 200.94


这篇关于绕过Math.round(200.925,2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆