Skip to content

Instantly share code, notes, and snippets.

@Logrythmik
Created July 19, 2012 22:02
Show Gist options
  • Save Logrythmik/3147177 to your computer and use it in GitHub Desktop.
Save Logrythmik/3147177 to your computer and use it in GitHub Desktop.
Human Friendly Filesize, from Double Extension Method
public static string GetFileSize(this double byteCount)
{
string size = "0 Bytes";
if (byteCount >= 1073741824.0)
size = String.Format("{0:##.##}", byteCount / 1073741824.0) + " GB";
else if (byteCount >= 1048576.0)
size = String.Format("{0:##.##}", byteCount / 1048576.0) + " MB";
else if (byteCount >= 1024.0)
size = String.Format("{0:##.##}", byteCount / 1024.0) + " KB";
else if (byteCount > 0 && byteCount < 1024.0)
size = byteCount.ToString() + " Bytes";
return size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment