From 4be7bb46f28822ee454a352c23ce8077b313c8b8 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Wed, 22 Jul 2015 11:52:05 +0200 Subject: [PATCH] Implemented negative values on si tagdisplay --- cloudcontrol/cli/tagdisplay.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cloudcontrol/cli/tagdisplay.py b/cloudcontrol/cli/tagdisplay.py index 7ada5d1..914d38c 100644 --- a/cloudcontrol/cli/tagdisplay.py +++ b/cloudcontrol/cli/tagdisplay.py @@ -138,14 +138,22 @@ class TagDisplay(object): def type_bit(self, value): '''Bit type''' - if value.isdecimal(): - v = float(value) + if value.startswith('-'): + value_without_minus = value[1:] + neg = True + else: + value_without_minus = value + neg = False + if value_without_minus.isdecimal(): + v = float(value_without_minus) if v >= 1000: si = "KMGTPEZY" p = min(math.floor(math.log(abs(v), 2)/10.0), pow(2, len(si))) d = v / pow(2, 10*p) u = si[int(p-1)] value = u"%.4g%si"%(d, u) + if neg: + value = u"-" + value return value def type_second(self, value): -- GitLab