can not apply operator * to operand of type decimal and double

前端 未结 1 756
你的背包
你的背包 2021-01-18 08:46

Hi I need to apply a discount of 5.2% on a product.I have tryed doing something like this:

decimal BasePrice {get;set;}
decimal Discount = (BasePrice * 5.2)          


        
相关标签:
1条回答
  • 2021-01-18 09:11

    Use

    decimal Discount = (BasePrice * 5.2m) / 100;
    

    Otherwise, 5.2 will be treated as a double.

    From MSDN:

    If you want a numeric real literal to be treated as decimal, use the suffix m or M

    0 讨论(0)
提交回复
热议问题