Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast int variable to double

Tags:

People also ask

What happens when you cast an int to a double?

Java compiler will automatically convert lower data type(int) to higher data type(double). Since higher data type has wider range and greater memory size than lower data type. It is called as implicit typecasting.

How do I cast an int to a double in C++?

if i'm not wrong you can directly assign an integer to a double in c++, there's no need to do an explicit casting. It's called "typecasting". int a = 5; double b = (double) a; double c = 4.0; int d = (int) c; chandra.

Can you cast int to double C#?

@Mitja no you can't; double.

Can we store int value in double in Java?

Double is bigger than int as it requires more storage space; hence, int values are implicitly converted to double by Java.


I am a beginner C# programmer, and I am trying to create a calculator. I can't seem to figure out how to cast an int variable to a double. This is what I have so far:

public void oImpartire() {
    if (rezultat % value == 0)
    {
        rezultat /= value;
    }
    else {
       (double)rezultat /= value;  // this should be double but I get an error
    }
}

How can I make this work?

EDIT: Both result and value are int variables.