/// <summary>
/// 只舍不如 默认保留两位有效数字
/// </summary>
/// <param name="obj">round函数有几个参数输入的数据</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);
/// 只舍不如 默认保留两位有效数字
/// </summary>
/// <param name="obj">round函数有几个参数输入的数据</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)
{
}
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>
/// 四舍五入 默认保留两位有效数字
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);
}
/// <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);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论