场景:
售票系统,VIP会员按折扣优惠,但折扣不同会产生零头,要求此类价格个位逢零头向上进位成整10。
解决办法:
/// <summary>
/// 数字个位逢1~9进成整10,如91转成100;98转成100;
/// </summary>
/// <param name="strValue">转换前参数</param>
/// <returns></returns>转换后结果
private string RoundEx(string strValue)
{
decimal decValue = 0;
string strResult = "";
try
{
decValue = Convert.ToDecimal(strValue);
strResult = Convert.ToString(Math.Ceiling(decValue/ 10) * 10);
}
catch
{
strResult = "0.00";
}
return strResult;
}
/// 数字个位逢1~9进成整10,如91转成100;98转成100;
/// </summary>
/// <param name="strValue">转换前参数</param>
/// <returns></returns>转换后结果
private string RoundEx(string strValue)
{
decimal decValue = 0;
string strResult = "";
try
{
decValue = Convert.ToDecimal(strValue);
strResult = Convert.ToString(Math.Ceiling(decValue/ 10) * 10);
}
catch
{
strResult = "0.00";
}
return strResult;
}