这应该很容易,但我不能找到一个内置的方法吧,.NET框架必须有一个方法来做到这一点!
私人小数RoundDownTo2DecimalPlaces(小数点输入)
{
如果(输入℃,)
{
抛出新的异常(不negitive号测试);
}
//必须有一个更好的办法!
返回Math.Truncate(输入* 100)/ 100;
}
解决方案
没有建立在.NET Framework中做到这一点的方法,其他的答案说怎么写自己的code。
This should be easy, but I can’t find a built in method for it, the .net framework must have a method to do this!
private decimal RoundDownTo2DecimalPlaces(decimal input)
{
if (input < 0)
{
throw new Exception("not tested with negitive numbers");
}
// There must be a better way!
return Math.Truncate(input * 100) / 100;
}
解决方案
There is no build in method in the .net framework to do this, other answers say how to write your own code.