humanize_speed: Only give one decimal number

a speed of 2048 would be rendered as "2.048 Mbps", where the decimal dot could be confused with a thousand separator. closes #10157
This commit is contained in:
Patrick Rauscher 2022-08-26 09:49:33 +02:00 committed by GitHub
parent 88d2fca2c6
commit 2fcb4afec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@ def humanize_speed(speed):
"""
Humanize speeds given in Kbps. Examples:
1544 => "1.544 Mbps"
1544 => "1.6 Mbps"
100000 => "100 Mbps"
10000000 => "10 Gbps"
"""
@ -61,7 +61,7 @@ def humanize_speed(speed):
elif speed >= 1000 and speed % 1000 == 0:
return '{} Mbps'.format(int(speed / 1000))
elif speed >= 1000:
return '{} Mbps'.format(float(speed) / 1000)
return '{:.1f} Mbps'.format(float(speed) / 1000)
else:
return '{} Kbps'.format(speed)