diff options
author | Nicolas Hennion <nicolashennion@gmail.com> | 2013-03-19 05:51:59 -0700 |
---|---|---|
committer | Nicolas Hennion <nicolashennion@gmail.com> | 2013-03-19 05:51:59 -0700 |
commit | 2a50b5f9ab41138491ee74dd243eeae576d95291 (patch) | |
tree | 83364c1ccd001911930abd1728c8670eb8d3cf8f | |
parent | a0e1380400c7be2e2b07265341ffe19591bfedd2 (diff) | |
parent | a0060f9b01fdc93bc799319da2e25c5e6b7ac775 (diff) |
Merge pull request #218 from jrenner/master
Tried to improve autoUnit
-rw-r--r-- | glances/glances.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/glances/glances.py b/glances/glances.py index 5e180597..2de48d5e 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -1475,13 +1475,18 @@ class glancesScreen: } for key in reversed(symbols): - if val >= prefix[key]: - value = float(val) / prefix[key] - if key == "M" or key == "K": - return "{0:.0f}{1}".format(value, key) + value = float(val) / prefix[key] + if value > 1: + fixed_decimal_places = 0 + if value < 100: + fixed_decimal_places = 1 + if value < 10: + fixed_decimal_places = 2 + val_string = "{0:.%df}{1}" % fixed_decimal_places + if key in 'YZEPTG': + return val_string.format(value, key) else: - return "{0:.1f}{1}".format(value, key) - + return "{0:.0f}{1}".format(value, key) return "{0!s}".format(val) def __getCpuAlert(self, current=0, max=100, stat=''): |