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.
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.
@Mitja no you can't; double.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With