Oct 6
Converting Bytes to Human Readable Value
/// <summary>
/// Round up to the best human readable number
/// (could be kb, mb or gb depending on size of
/// number
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public string BytesToHumanReadable(double bytes)
{
var gig = Math.Pow(1024, 3);
var meg = Math.Pow(1024, 2); if(bytes > gig)
return Math.Round(bytes / gig, 1) + " GB";
else if (bytes > meg)
return (int)(bytes / meg ) + " MB";
else
return (int)(bytes / 1024 ) + " KB"; }
This is useful for file and memory sizes.
