【发布时间】:2010-09-26 10:10:36
【问题描述】:
这应该很容易,但是我找不到内置方法,.net框架必须有方法才能做到这一点!
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;
}
【问题讨论】:
-
您要舍入小数本身还是文本表示?
-
@Henk,我需要将值输出为文本,但宁愿在输出之前进行舍入。很可能该值稍后必须输入到其他计算中。
-
你真的接受你自己的帖子作为答案,而它甚至没有代码吗?大声笑
-
@codemonkeyliketab 他似乎非常需要这些点......