After the test found that the Math.Round function exists this problem, using the "four homes six into 50% pairs" of the way
Specific reference: http://blog.joycode.com/ghj/posts/9474.aspx
For example: Math.Round (1.5) = 2
Math.Round (2.5) = 2
SQL Server uses the traditional rounding method, in order to ensure that the foreground program and the background of the calculation of the database consistent.
So there's a class and two static methods added to public
You can use the following: Mymath.round () method to replace the Math.Round () method
public static decimal Round (decimal number)
{
Return Emsmath.round (number,0);
}
public static decimal Round (decimal number, int dec)
{
String numstr = number. ToString ();
if (numstr = = "0") return (decimal) 0.0;
int decindex = Numstr.indexof (".", 0);
if (numstr.length <= decindex + Dec + 1)
return number;
String decstr = numstr.substring (decindex + Dec + 1);
Decstr = Decstr.replace ("0", "");
if (Decstr = = "5")
{
int lastnum;
if (dec = 0)
lastnum = Int. Parse (numstr.substring (decindex-1,1));
Else
lastnum = Int. Parse (numstr.substring (Decindex + dec,1));
if (lastnum% 2 = 0)
{
Decimal Addnumer = (decimal) 1.0;
for (int i = 0; i < Dec; i + +)
{
Addnumer = Addnumer * (decimal) 0.1;
}
return Math.Round (NUMBER,DEC) + Addnumer;
}
Else
return Math.Round (NUMBER,DEC);
}
else
return Math.Round (NUMBER,DEC);
}