double 转 byte[] 的问题
代码在下面,主要问题是某些数据会出现转换错误,比如700~10W之间的数字转换就错误,但是小数或者大数可以转换成功,求教是什么问题?public static byte[] putDouble( double x) {
byte[] b = new byte[8];
long l = Double.doubleToLongBits(x);
for (int i = 0; i < 8; i++) {
b[i] = new Long(l).byteValue();
l = l >> 8;
}
return b;
}
public static double getDouble(byte[] b) {
long m;
m = b[0];
m &= 0xff;
m |= ((long) b[1] << 8);
m &= 0xffff;
m |= ((long) b[2] << 16);
m &= 0xffffff;
m |= ((long) b[3] << 24);
m &= 0xffffffffl;
m |= ((long) b[4] << 32);
m &= 0xffffffffffl;
m |= ((long) b[5] << 40);
m &= 0xffffffffffffl;
m |= ((long) b[6] << 48);
m &= 0xffffffffffffffl;
m |= ((long) b[7] << 56);
return Double.longBitsToDouble(m);
} 数据 转换 byte[] double --------------------编程问答-------------------- 你这是要做甚?
大数用 bigDecimal
补充:Java , Java EE