public static string FormatFileSize(long Size) { string[] Suffixes = new string[] { "B", "KB", "MB", "GB", "TB" }; int SuffixIndex = 0; double WorkingSize = (double)Size; while (WorkingSize > 0 && SuffixIndex < Suffixes.Length) { WorkingSize /= 1024; } if (WorkingSize < 0 && SuffixIndex > 0) { WorkingSize *= 1024; SuffixIndex--; } return string.Format("{0:0.00} {1}", WorkingSize, Suffixes[SuffixIndex]); }