Skip to content

Commit

Permalink
reduce decimal places to increase readability
Browse files Browse the repository at this point in the history
  • Loading branch information
redsuns-chan committed Jul 29, 2022
1 parent 58e89ba commit 1a2ac7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hex-to-float-covertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main(file_path: str, big_endian: bool):
f = open(file_path, "r")
file_size = stat(file_path).st_size
content = f.read(file_size)
content = content.replace(" ", "")
content = content.replace(" ", "").replace("\n", "").replace("\r", "")
converted = []
i = 0
while (i <= file_size):
Expand All @@ -20,7 +20,7 @@ def main(file_path: str, big_endian: bool):
le_bytes = bytearray.fromhex(n)
if big_endian == False:
le_bytes.reverse()
converted.append(struct.unpack('!f', le_bytes)[0])
converted.append(float("{:.2f}".format(struct.unpack('!f', le_bytes)[0])))
i += 8
f.close()
print(converted)
Expand Down

0 comments on commit 1a2ac7a

Please sign in to comment.