java 类型转换:

数值数据类型:

1.自动类型转换

  byte->short ->int->long-->float--->double

  范转小的类型向范围大的类型号转换,由系统自动完成  [不会丢失精度],

      但loat和double在进行转换时候,有可能损失精度

  但byte和short 运算系统自动转换成int

  eg:   

      byte b=20;

      short s=b;

      s=s+b;    //b->short + b=40        //40转换为int  会出错误:高级不能换为低级类型

      特例:byte 与short 进行 算术运算时,他们结果转换为int

 

2.强制类型转换

    byte<-short <-int<-ong<-float<-double

   (转换类型)数值

     当数值在 (转换类型范围内),不丢数据

     当数值在 (转换类型范围外),丢数据,不准确

     

原文地址:https://www.cnblogs.com/zengkefu/p/5583107.html