Last active
May 19, 2019 14:26
-
-
Save leyle/6df5cf0bb5dfc7d8a9f2 to your computer and use it in GitHub Desktop.
字节单位转换
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def size_human(size): | |
| if size < 1024: | |
| size = "%ldByte" % size | |
| return size | |
| elif size < 1048576: | |
| size = "%.2fKB" % (size / 1024.0) | |
| return size | |
| elif size < 1073741824: | |
| size = "%.2fMB" % (size / 1048576.0) | |
| return size | |
| else: | |
| size = "%.2fGB" % (size / 1073741824.0) | |
| return size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment