using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.Core.Helpers { public static class FileHelper { public static String GetFriendlyFileSize(long fileSize) { string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB if (fileSize == 0) return "0" + suf[0]; long bytes = Math.Abs(fileSize); int place = System.Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); double num = Math.Round(bytes / Math.Pow(1024, place), 1); return (Math.Sign(fileSize) * num).ToString() + " " + suf[place]; } } }