Python Forum

Full Version: hexaecimal float
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
is there a way to get a float formatted in hexadecimal?
Use methods hex() and fromhex()
>>> from math import pi
>>> pi.hex()
'0x1.921fb54442d18p+1'
>>> s = pi.hex()
>>> 
>>> float.fromhex(s)
3.141592653589793
>>> float.fromhex(s) == pi
True
>>> 
so, all you are using math for is to get a float value instead of just using: v = 10.0**9+1/10**9?

edit:

v = 10.0**3+1/10**3 would be better.