简体   繁体   中英

Using operators with certain types

I am trying to do the equation answer < 10 && answer > 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'

In my code,

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

X is equal to whatever the user inputs in a text box.

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>

The var "answer" is of the type int and you're trying to compare 10(of type int) and 0.9(of type 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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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