Уроки C# – Получаем читаемый размер
Added 2022-08-08 10:52:54 +0000 UTCУроки C# – Получаем читаемый размер
string Sizer(double countBytes){
string[] type = { "B", "KB", "MB", "GB" };
if (countBytes == 0)
return $"0 {type[0]}";
double bytes = Math.Abs(countBytes);
int place = (int)Math.Floor(Math.Log(bytes, 1024));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return $"{Math.Sign(countBytes) * num} {type[place]}";
}