The process of changing a value from one type to another type when a type is converted.
converting from a low-precision data type to a high-precision data type never overflows and is always successful.
The conversion of high-precision data types to low-precision data types will inevitably result in information loss and possibly failure.
There are two ways to convert data types, implicit type conversions and explicit type conversions (/////* These two symbols represent annotations):
implicitly-typed conversions:
conversions from low-level types to advanced types are performed automatically, and programmers do not need to do anything, and this type of conversion is called implicit conversion.
Of course, the logical type and character type are not included, and the base data type is ranked as byte<short<int<long<float<double from low to high precision .
an explicit type conversion:
when assigning high-precision variable values to low-precision variables, the display type conversion (also called coercion type conversion) must be used.
Public class test{//Create Class
Public static void Main (string[] args) {//Main method
int number1 = 1; declares an int variable and assigns a value of 1
float number2 = number1; Declares a float variable and assigns a value of number1 the implicit type conversion is used here
int number3 = (int) 12.34; The explicit type conversion is used here and the output value is
}
}
PS: When converting an integer into a type, you can exceed the range of values to be converted, and you must cast the type. (such as: byte B = (byte) 129; here byte equals-127, for specific reasons, please Baidu understand)
<java Basic > data Type conversion <5>