Converting between two different data types is called casting, and it looks like this in practice:
(int) 11.0 // = 11 (int) 11.84 // = 11 (double) 11 // = 11.0 (double) 11/2 // = 5.5
Or this generally:
Casting has to do with how the computer stores
If you want the computer to store more information than it had been, as when you convert an
int i = 94; double d = i; d; // d = 94.0
If you want to store less information, like going from a
double to an
int, you need to tell the computer you understand you're dropping information – you need to cast.
double d = 94.19; int i = (int) d; i; // i = 94
(int) is the cast: it's shorthand for "make whatever is on the right of the parentheses into an int."
If you try the same calculation without a cast:
double d = 94.19; int i = d; ERROR: Type mismatch: cannot convert from double to int
Here's a few other examples:
|n||(int) n||(double) n|
|2.5 * 12||27||27.5|