Improve formating of size function and test it
This commit is contained in:
parent
969210a723
commit
e837f9c8e5
2 changed files with 20 additions and 4 deletions
|
|
@ -32,10 +32,9 @@ def size(size, unit=True):
|
|||
units = ['B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']
|
||||
p = math.floor(math.log(size, 2) / 10)
|
||||
|
||||
if unit:
|
||||
return "%.3f %s" % (size / math.pow(1024,p), units[int(p)])
|
||||
else:
|
||||
return "%.3f" % (size / math.pow(1024,p))
|
||||
s = size / math.pow(1024, p)
|
||||
r = size % math.pow(1024, p)
|
||||
return (("%.3f" if r else "%.0f") % s) + ((" " + units[int(p)]) if unit else "")
|
||||
|
||||
|
||||
def word_distance(str1, str2):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue