Created
June 15, 2013 08:13
-
-
Save sphingu/5787361 to your computer and use it in GitHub Desktop.
Readable File Size
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 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