是否可以在 Python 中解析从 Java Double.toHexString 方法编写的字符串?
http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toHexString(double)
输出如下所示:“0x1.16d6b97e718ffp8” ...不确定这是否是标准化格式。
我期望类似的东西
value=float('0x1.16d6b97e718ffp8')
最佳答案
那就是float.fromhex
:
>>> float.fromhex('0x1.16d6b97e718ffp8')
278.8387679126026
来自文档:
This syntax is similar to the syntax specified in section 6.4.4.2 of the C99 standard, and also to the syntax used in Java 1.5 onwards. In particular, the output of
float.hex()
is usable as a hexadecimal floating-point literal in C or Java code, and hexadecimal strings produced by C’s%a
format character or Java’sDouble.toHexString
are accepted byfloat.fromhex()
.
关于java - Python 解析 Java Double.toHexString(double) 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21768587/