Operator '*' cannot be applied to operands of type 'double' and 'decimal'

前端 未结 4 2015
北荒
北荒 2020-12-07 00:39

I get this message in my program but i don\'t know how to fix it i have search on the net but don\'t find any thing that can help me.

private double Price;
p         


        
相关标签:
4条回答
  • 2020-12-07 00:44

    Change foodVATRate to decimal, too. There doesn't seem to be any reason for it to be double.

    0 讨论(0)
  • 2020-12-07 00:48

    You can't multiply a decimal by a double. You can fix this by type casting, but you probably just want to stick with using decimal for all prices and VAT rates throughout.

    The type decimal was designed to be useful for financial calculations since it offers high precision at the cost of reduced range for the size of the type in bytes.

    0 讨论(0)
  • 2020-12-07 00:49

    Try this:

    Rate = (decimal)Vat * Finalprice;
    
    0 讨论(0)
  • 2020-12-07 01:08

    You need to cast one to the other. My guess is that both Price and all of your VAT rates should really be decimal - double isn't (usually) appropriate for dealing with any type of monetary values.

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