Skip to content

Instantly share code, notes, and snippets.

@sphingu
Created June 15, 2013 08:13
Show Gist options
  • Save sphingu/5787361 to your computer and use it in GitHub Desktop.
Save sphingu/5787361 to your computer and use it in GitHub Desktop.
Readable File Size
public static String readableFileSized(long size)
{
long bytes = size;
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB" };
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
string readable = num.ToString() + suf[place];
return readable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment