From 2fcb4afec373bf490cc91e4445bd660f15e939c6 Mon Sep 17 00:00:00 2001 From: Patrick Rauscher Date: Fri, 26 Aug 2022 09:49:33 +0200 Subject: [PATCH] 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 --- netbox/utilities/templatetags/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 67ed553b2..bc76c62d5 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -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)