public class Test {
public static void main(String args[]){
long l1 =8589934592L;
float f1= l1;
long l2= (long)f1;
System.out.println("Input long::"+l1);
System.out.println("Float value::"+f1);
System.out.println("Typecasted value::"+l2);
}
}
Output of for first class:
Input long::8589934592
Float value::8.5899346E9
Typecasted value::8589934592
例2:
public class Test {
public static void main(String args[]){
long l1 =6788819226L;
float f1= l1;
long l2= (long)f1;
System.out.println("Input long::"+l1);
System.out.println("Float value::"+f1);
System.out.println("Typecasted value::"+l2);
}
}
Output of for second class:
Input long::6788819226
Float value::6.7888195E9
Typecasted value::6788819456
鑄字沒有發生正常。兩個類都有不同的行爲。 爲什麼示例2在類型轉換後具有不同的值。請讓我知道原因?