Skip to content

Instantly share code, notes, and snippets.

@eddieespinal
Created November 6, 2014 22:20
Show Gist options
  • Select an option

  • Save eddieespinal/068a87d922121bdb5478 to your computer and use it in GitHub Desktop.

Select an option

Save eddieespinal/068a87d922121bdb5478 to your computer and use it in GitHub Desktop.
Convert Bytes to KB, MB, GB, TB
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