0
我不确定它是否只是我,但这似乎有点不可思议。我有一个静态类中的一些扩展舍入值:扩展和十进制和双之间的冲突
public static double? Round(this double? d, int decimals)
{
if (d.HasValue)
return Math.Round(d.Value, decimals, MidpointRounding.AwayFromZero);
return null;
}
public static double? Round(this double d, int decimals)
{
return Math.Round(d, decimals, MidpointRounding.AwayFromZero);
}
我最近增加了同为四舍五入小数:
public static decimal? Round(this decimal? d, int decimals)
{
if (d.HasValue)
return Math.Round(d.Value, decimals, MidpointRounding.AwayFromZero);
return null;
}
public static decimal? Round(this decimal d, int decimals)
{
return Math.Round(d, decimals, MidpointRounding.AwayFromZero);
}
我希望没有人能看到什么错,在这一点上。当我的代码
var x = (decimal)0;
var xx = x.Round(0);
的CLR引发错误会员“decimal.Round(十进制)”不能以一个实例引用来访问它出现;用类型名称代替它
WTF?如果我只是重命名我的小数四舍五入扩展(例如称为RoundDecimal),一切工作正常。似乎CLR不知何故混淆了双精度和十进制方法..任何人都可以解释这一点吗?
有趣的是,如果我叫圆(X,0)代替,它工作正常...