在C#中,Math.Round和decimal.Round函数有什么区别?
没有区别。
Math.Round(decimal)
源代码:
public static Decimal Round(Decimal d) {
return Decimal.Round(d,0);
}
为了澄清,这是decimal.cs
类的源代码:
public static Decimal Round(Decimal d) {
return Round(d, 0);
}
Math.Round
中,有效数字的数量被设置为0,这是有所不同的。 - Haneydecimal.Round(Decimal d)
做的事情是一样的。 - Justin Loveless是的,就答案而言没有区别,但传递值是不同的。 Math.Round接受double和float类型,但decimal.Round仅接受decimal结构体。
Math.Round(decimal)
调用Decimal.Round(decimal)
。http://referencesource.microsoft.com/#mscorlib/system/math.cs,85130852558b2bc9 - Slai