Created
July 19, 2012 22:02
-
-
Save Logrythmik/3147177 to your computer and use it in GitHub Desktop.
Human Friendly Filesize, from Double Extension Method
This file contains 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
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