Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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) / 100;

But Visual Studio tells me that it :

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

If that is so how can I represent this discount?

like image 350
aleczandru Avatar asked Apr 11 '13 08:04

aleczandru


1 Answers

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

like image 64
sloth Avatar answered Oct 15 '22 19:10

sloth