嗨,我需要在产品上申请5.2%的折扣.我尝试过这样的事情:
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