2 回答
TA贡献1785条经验 获得超8个赞
将您的代码更改为
Double object = new Double("2.4");
int a = object.intValue();
byte b = object.byteValue();
float d = object.floatValue();
double c = object.doubleValue();
System.out.println(a);
System.out.println(a + b);
System.out.println(a + b + c);
System.out.println(a + b + c + d );
并探索
TA贡献1775条经验 获得超11个赞
如果有人仍在寻找为什么 15 位小数精度出现的答案。
public class JavaExample {
public static void main(String[] args) {
Double object = new Double("2.4");
int a = object.intValue();
byte b = object.byteValue();
float c = object.floatValue();
double d = object.doubleValue();
float e = object.floatValue();
double f = object.doubleValue();
System.out.println("int :"+a);
System.out.println("int and byte addition :"+(a + b));
System.out.println("int, byte and float addition :"+(a + b + d));
System.out.println("int, byte, float and double addition :"+(a + b + c + d));
System.out.println("float and double addition :"+(c + d));
System.out.println("float and float addition :"+(c + e));
System.out.println("double and double addition :"+(d + f));
System.out.println("float and double addition :"+(e + f));
}
}
Output:
int :2
int and byte addition :4
int, byte and float addition :6.4
int, byte, float and double addition :8.800000095367432
float and double addition :4.800000095367432
float and float addition :4.8
double and double addition :4.8
float and double addition :4.800000095367432
添加回答
举报