Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hexaecimal float
#1
is there a way to get a float formatted in hexadecimal?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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
>>> 
Skaperen likes this post
Reply
#3
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.
Gribouillis likes this post
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 293 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,397 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020