-
-
Save jrt324/4f7752fa4bfc8f99a89ee98340831b3e to your computer and use it in GitHub Desktop.
File size friendly display
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
private string ToFileSizeString(long size) | |
{ | |
string result; | |
if (size < 1000L) | |
{ | |
result = string.Format("{0} bytes", size); | |
} | |
else if (size < 1000000L) | |
{ | |
result = string.Format("{0:F1} KB", (double)size / 1000.0); | |
} | |
else if (size < 1000000000L) | |
{ | |
result = string.Format("{0:F1} MB", (double)size / 1000000.0); | |
} | |
else if (size < 1000000000000L) | |
{ | |
result = string.Format("{0:F1} GB", (double)size / 1000000000.0); | |
} | |
else if (size < 1000000000000000L) | |
{ | |
result = string.Format("{0:F1} TB", (double)size / 1000000000000.0); | |
} | |
else | |
{ | |
result = size.ToString(CultureInfo.InvariantCulture); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment