>> 不抱怨,不妒忌,潇洒做自己!

c# RoundUp函数

工作需要,写了一个,RoundDown和Round有时间再补上。

 

private static decimal RoundUp(decimal val, int decPoint)
{
bool flagMinus = false;
if (val < 0)
{
val
= -val;
flagMinus
= true;
}

decimal newVal = Math.Round(val, decPoint);
decimal difference = val - newVal;
if (difference > 0)
{
decimal padding = 1 / (decimal)(Math.Pow(10, decPoint));
newVal
+= padding;
}
if (flagMinus)
return newVal * -1;
else
return newVal;
}

 

posted @ 2010-07-23 11:04  loose_went  阅读(1312)  评论(1编辑  收藏  举报