简体   繁体   English

使用某些类型的运算符

[英]Using operators with certain types

I am trying to do the equation answer < 10 && answer > 0.9. 我试图做方程答案<10 &&答案> 0.9。 Then if this is true do something. 然后,如果是这样,请执行某些操作。

if (answer < 10 && answer > 0.9)
                        {

                        }

But I get the error "Operator '>' cannot be applied to operands of type 'decimal' and 'double' 但我收到错误消息“运算符'>'无法应用于类型为'decimal'和'double'的操作数

In my code, 在我的代码中

var y = 1000000;
var answer = x*y;

X is equal to whatever the user inputs in a text box. X等于用户在文本框中输入的值。

I don't know where I am getting double from to be honest. 老实说,我不知道我从哪里得到了双重收益。 Maybe it is what my answer becomes if it becomes too large? 如果它变得太大,也许这就是我的答案? And how can I make the if statement work> 以及如何使if语句起作用>

The var "answer" is of the type int and you're trying to compare 10(of type int) and 0.9(of type double) var“答案”的类型为int,并且您尝试比较10(int类型)和0.9(double类型)

Try: 尝试:

var y = 1000000;
var answer = Convert.ToDouble(x*y);

and

if (answer < 10.0 && answer > 0.9)

and i think that will work :) 而且我认为这会起作用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM