/// <summary>
/// 只舍不如 默认保留两位有效数字
/// </summary>
/// <param name="obj">输入的数据</param>
/// <param name="i">保留的小数位</param>
/// <returns></returns>
public static decimal ExShe(decimal obj, int i)
{
string str = "0.";
for (int j = 0; j < i; j++)
{
str += "0";
}
str += "5";
decimal dec = Convert.ToDecimal(str);
return Ex4s5R(obj - dec, i);
}
public static decimal ExShe(decimal obj)
{
return ExShe(obj, 2);
}
/// <summary>
/// 只入不舍 默认保留两位有效数字
/// </summary>
/// <param name="obj"></param>
/// <param name="i"></param>
/// <returns></returns>
public static decimal ExRu(decimal obj, int i)
{
string str = "0.";
for (int j = 0; j < i; j++)
{
str += "0";
}
str += "4";
decimal dec = Convert.ToDecimal(str);
return Ex4s5R(obj+dec,i);
}
public static decimal ExRu(decimal obj)
{
return ExRu(obj, 2);
}
/// <summary>
/// 四舍五入 默认保留两位有效数字
/// </summary>
/// <param name="obj"></param>
/// <param name="i"></param>
/// <returns></returns>
public static decimal Ex4s5R(decimal obj, int i)
{
return Math.Round(obj, i, MidpointRounding.AwayFromZero);
}
public static decimal Ex4s5R(decimal obj)
{
return Ex4s5R(obj, 2);
}