I have a floating point number stored in a binary file 0.9999833107. When I read the number in it is either truncated or extended depending on whether I use float or double to store it. I read in the binary with the following code:
public double readFloat(RandomAccessFile fp){
byte[] data = new byte[4];
try {
data[0] = fp.readByte();
data[1] = fp.readByte();
data[2] = fp.readByte();
data[3] = fp.readByte();
} catch (IOException e) {
e.printStackTrace();
return 0;
}
ByteBuffer buffer = ByteBuffer.wrap(data);
return buffer.getDouble();
}
This method returns 0.9999833106994629. When I change the method to output a float the value returned is 0.9999833. Does anyone have any idea how I can get the number out that was written into the file?