如何在 Python 中反转 float.hex() 方法
How to reverse the float.hex() method in Python
有没有办法反转 Python 中 float
的 hex()
方法?例如,
n = 1280.03125
n_hex = n.hex()
print(n_hex) # result--> 0x1.4002000000000p+10
如何将 0x1.4002000000000p+10
转换回 1280.03125
?我知道您可以使用 int(num, base)
将数字转换为整数,但它不支持小数。
尝试 float.fromhex(str)
:
>>> float.fromhex("0x1.4002000000000p+10")
1280.03125
有没有办法反转 Python 中 float
的 hex()
方法?例如,
n = 1280.03125
n_hex = n.hex()
print(n_hex) # result--> 0x1.4002000000000p+10
如何将 0x1.4002000000000p+10
转换回 1280.03125
?我知道您可以使用 int(num, base)
将数字转换为整数,但它不支持小数。
尝试 float.fromhex(str)
:
>>> float.fromhex("0x1.4002000000000p+10")
1280.03125