NokiMo
Хачатур
Хачатур

boosty


Уроки C# – Получаем читаемый размер

Уроки 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]}";
}


Related Creators