问题描述
C#和sql server中的math.round是否相同.
我已经检查了以下内容,但我不了解Math.Round函数在C#中的工作方式.
Sql Server:
选择convert(varchar,convert(numeric(18,2),224.025000000))输出224.03
C#:
Math.Round(224.025000000))输出224.02
但是
Math.Round(2.345,2)输出2.35
Math.Round(2.245,2)输出2.24
谁能说出以上两个语句的输出为何不同?
在此先感谢.
Does math.round in C# and sql server are the same.
I have check the following, but I didn''t understand how the Math.Round function is working in C#.
Sql Server:
select convert(varchar,convert(numeric(18,2),224.025000000 )) Output 224.03
C#:
Math.Round(224.025000000)) Output 224.02
But
Math.Round(2.345, 2) Output 2.35
Math.Round(2.245, 2) Output 2.24
Can anybody tell Why the outputs of above two statements are different ?
Thanks in advance.
推荐答案
Math.Round(224.02500000, 2,MidpointRounding.AwayFromZero)
参考: http://msdn.microsoft.com/en-us/library/system.midpointrounding. aspx [^ ]
Ref:http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx[^]
这篇关于C#和Sql Server中的Math.Round的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!