Created
November 6, 2014 22:20
-
-
Save eddieespinal/068a87d922121bdb5478 to your computer and use it in GitHub Desktop.
Convert Bytes to KB, MB, GB, TB
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
| function bytesToSize(bytes) | |
| { | |
| if (bytes == 0) | |
| { | |
| return "0 Byte"; | |
| } | |
| local k = 1000; | |
| local sizes = ["Bytes", "KB", "MB", "GB", "TB"]; | |
| local i = math.floor(math.log(bytes) / math.log(k)); | |
| return math.abs(bytes / math.pow(k, i)) + "" + sizes[i]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment