decimal BasePrice {get;set;}decimal discount = (BasePrice * 5.2) / 100;
但Visual Studio告诉我它:
can not apply operator ‘*’ to operand of type decimal and double
如果是这样我怎么能代表这个折扣?
解决方法 使用decimal discount = (BasePrice * 5.2m) / 100;
否则,5.2将被视为双精度.
从MSDN开始:
总结If you want a numeric real literal to be treated as decimal,use the suffix m or M
以上是内存溢出为你收集整理的c# – 不能将operator *应用于decimal和double类型的 *** 作数全部内容,希望文章能够帮你解决c# – 不能将operator *应用于decimal和double类型的 *** 作数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)