Java数值型数据类型由低级到高级排序为:byte->short->int->long->float->double
1、低级到高级的自动类型转换
低级变量可以直接转换成高级变量。
2、高级到低级的强制类型转换
强制转换如:byte b = (byte)i;强制转换可能会导致精度的下降。
数据类型 | 所占空间 |
byte | 8位 |
short | 16位 |
int | 32位 |
long | 64位 |
float | 32位 |
double | 63位 |
Java数值型数据类型由低级到高级排序为:byte->short->int->long->float->double
1、低级到高级的自动类型转换
低级变量可以直接转换成高级变量。
2、高级到低级的强制类型转换
强制转换如:byte b = (byte)i;强制转换可能会导致精度的下降。
数据类型 | 所占空间 |
byte | 8位 |
short | 16位 |
int | 32位 |
long | 64位 |
float | 32位 |
double | 63位 |