我在使用Python进行二进制文件写入时,对于浮点型数据的打包和解包遇到了一些问题。以下是我的操作:
import struct
f = open('file.bin', 'wb')
value = 1.23456
data = struct.pack('f',value)
f.write(data)
f.close()
f = open('file.bin', 'rb')
print struct.unpack('f',f.read(4))
f.close()
我得到的结果如下: The result I get is the following:
(1.2345600128173828,)
这些额外的数字是怎么回事?这是一个四舍五入误差吗?这是如何工作的?