"c# bytes to kilobyes" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "c# bytes to kilobyes" answered properly. Developers are finding an appropriate answer about c# bytes to kilobyes related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like c# bytes to kilobyes. Enter your desired code related query in the search bar and get every piece of information about C# code related question on c# bytes to kilobyes. 

c# bytes to kilobyes

By Agreeable AntelopeAgreeable Antelope on Mar 10, 2021
//StackOverflow JLRishe
static readonly string[] SizeSuffixes = 
                   { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
static string SizeSuffix(Int64 value, int decimalPlaces = 1)
{
    if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException("decimalPlaces"); }
    if (value < 0) { return "-" + SizeSuffix(-value, decimalPlaces); } 
    if (value == 0) { return string.Format("{0:n" + decimalPlaces + "} bytes", 0); }

    // mag is 0 for bytes, 1 for KB, 2, for MB, etc.
    int mag = (int)Math.Log(value, 1024);

    // 1L << (mag * 10) == 2 ^ (10 * mag) 
    // [i.e. the number of bytes in the unit corresponding to mag]
    decimal adjustedSize = (decimal)value / (1L << (mag * 10));

    // make adjustment when the value is large enough that
    // it would round up to 1000 or more
    if (Math.Round(adjustedSize, decimalPlaces) >= 1000)
    {
        mag += 1;
        adjustedSize /= 1024;
    }

    return string.Format("{0:n" + decimalPlaces + "} {1}", 
        adjustedSize, 
        SizeSuffixes[mag]);
}

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the C# based application and are stuck on c# bytes to kilobyes can get a collection of related answers to their query. Programmers need to enter their query on c# bytes to kilobyes related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c# bytes to kilobyes for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of c# bytes to kilobyes while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "c# bytes to kilobyes". Visit this developer's friendly online web community, CodeProZone, and get your queries like c# bytes to kilobyes resolved professionally and stay updated to the latest C# updates. 

C# answers related to "c# bytes to kilobyes"

View All C# queries

C# queries related to "c# bytes to kilobyes"

Browse Other Code Languages

CodeProZone