好吧,我有这样的代码:奇怪的错误“操作符‘*’不能应用于类型‘双’和‘小数’的操作数”
decimal jewels = numericUpDown1.Value;
int price = 0.35/100 * jewels;
MessageBox.Show(price.ToString());
但出于某种奇怪的原因,我得到这个错误:`
operator '*' cannot be applied to operands of type 'double' and 'decimal'`.
我试过使用所有不同的类型,如float,double和int,它们都不起作用!
任何想法?
您不能乘以一个“小数”和“双”二rectly。 ('0.35/100'是'双')。先将'double'转换为'decimal',反之亦然。 – 2014-09-27 10:46:36
通过使它们都是相同的类型来简化它 - 然后再回到int。 int i = Convert.ToInt32(0.35m * 100m) – kidshaw 2014-09-27 11:13:09