As the name implies, type conversion means converting to a type different from the originally defined type. For example, I want to convert int type to double type! I think there is (or vice versa).
The former is
int num1 = 10;
double num2;
num2 = num1;
It will be. Type conversion that is just assigned is called "implicit type conversion". There is also a reverse pattern, but if you do the following, you will get an error.
double num1 = 3.14;
int num2;
num2 = num1;
This is because the range of double type is narrower than that of int type, which may reduce the accuracy. If you want to do this type conversion, do the following: However, the numbers after the decimal point are truncated.
double num1 = 3.14;
int num2;
num2 = (int)num1;
Recommended Posts