diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-11-19 10:35:04 -0800 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-11-19 10:35:04 -0800 |
commit | fe17d3517482525527d4af9b24df64e7651ebe3a (patch) | |
tree | 264f23f9c47115d8edaf8574988b17c936240d4e /glanceclient/common/utils.py | |
parent | b24832c22aa44d2f8b5ecddaf12e7878653af28f (diff) | |
download | python-glanceclient-fe17d3517482525527d4af9b24df64e7651ebe3a.tar.gz |
Simplify human-readable size output
* Limit human-readable sizes to a single decimal
* Drop trailing zero
* Step one suffix further in the case of a size being 1024
Change-Id: I2eb8ac0571d3d08b52f62155912863870573a37c
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r-- | glanceclient/common/utils.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 628225d..ac4eef8 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -175,8 +175,11 @@ def make_size_human_readable(size): base = 1024.0 index = 0 - while size > base: + while size >= base: index = index + 1 size = size / base - return "%.3f%s" % (size, suffix[index]) + padded = '%.1f' % size + stripped = padded.rstrip('0').rstrip('.') + + return '%s%s' % (stripped, suffix[index]) |