public static string ToFriendlyFileSize(long bytes)
{
if(bytes < 1024)
{
return bytes + " B";
}
else if(bytes < 1024 * 1024)
{
var converted = Math.Round(bytes / 1024.0, 1);
return converted + " KB";
}
else if (bytes < 1024 * 1024 * 1024)
{
var converted = Math.Round(bytes / (1024.0 * 1024.0) , 1);
return converted + " MB";
}
else
{
var converted = Math.Round(bytes / (1024.0 * 1024.0 * 1024.0), 1);
return converted + " GB";
}
}