Last active
August 29, 2015 14:11
-
-
Save maftieu/9a3d1532aa968e68f6a2 to your computer and use it in GitHub Desktop.
C# - FormatFileSize
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
static string FormatFileSize(long value, string format = null) | |
{ | |
var multipliers = new string[] { "o", "Kio", "Mio" }; | |
var midx = 0; | |
while ((Math.Abs(value) >= 1024) && (midx < multipliers.Length)) | |
{ | |
value /= 1000; | |
++midx; | |
} | |
var unit = multipliers[midx]; | |
return string.Format("{0} {1}", value.ToString(format ?? ""), unit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment