Improved pretty print output

This commit is contained in:
Mark Qvist 2023-10-24 13:24:40 +02:00
parent af3cc3c5dd
commit 38236366cf

View File

@ -192,15 +192,19 @@ def prettyfrequency(hz, suffix="Hz"):
return "%.2f%s%s" % (num, last_unit, suffix)
def prettydistance(hz, suffix="m"):
num = hz*1e6
units = ["µ", "m", "", "K","M","G","T","P","E","Z"]
last_unit = "Y"
def prettydistance(m, suffix="m"):
num = m*1e6
units = ["µ", "m", "c", ""]
last_unit = "K"
for unit in units:
if abs(num) < 1000.0:
divisor = 1000.0
if unit == "m": divisor = 10
if unit == "c": divisor = 100
if abs(num) < divisor:
return "%.2f %s%s" % (num, unit, suffix)
num /= 1000.0
num /= divisor
return "%.2f %s%s" % (num, last_unit, suffix)