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;
}