日期:2014-05-18 浏览次数:20793 次
/// <summary> /// 小数位数计算 /// </summary> /// <param name="je">数值</param> /// <param name="xsw">小数位</param> /// <param name="jefs">0.四舍五入1.进1法 2.舍1法 3.下取整四舍六入五成双</param> /// <remarks></remarks> public static double f_round(double je, int xsw, int jefs) { switch (jefs) { case 0: //四舍五入 return Math.Round(je, xsw, MidpointRounding.AwayFromZero); case 1: //进1(上取整) string str = "1"; for (int i = 1; i <= xsw; i++) { str += "0"; } int temp1 = Convert.ToInt32(str); return Math.Floor(je * temp1) / temp1; case 2: //舍1(下取整) break; case 3: //四舍六入五成双 break; } }
------解决方案--------------------
那就试试这个:
decimal d = 10.45446m;
Math.Ceiling(d * 100) / 100
OR
Math.Round(d + 0.005)
------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.math.round(VS.80).aspx
double d = Math.Round(10.45446, 2, MidpointRounding.AwayFromZero);