I was refactoring some old code and came across the following line of code to convert bytes to GB.
decimal GB = KB / 1024 / 1024 / 1024;
Is
#region AutoFileSize
public string AutoFileSize(long number)
{
double tmp = number;
string suffix = " B ";
if (tmp > 1024) { tmp = tmp / 1024; suffix = " KB"; }
if (tmp > 1024) { tmp = tmp / 1024; suffix = " MB"; }
if (tmp > 1024) { tmp = tmp / 1024; suffix = " GB"; }
if (tmp > 1024) { tmp = tmp / 1024; suffix = " TB"; }
return tmp.ToString("n") + suffix;
}
#endregion
long number = (long)fu.PostedFile.ContentLength;