public static void Main()
Console.WriteLine(FormatSpeed(100.0, 10.0));
Console.WriteLine(FormatSpeed(1000.0, 10.0));
Console.WriteLine(FormatSpeed(2000.0, 10.0));
Console.WriteLine(FormatSpeed(1024000.0, 10.0));
Console.WriteLine(FormatSpeed(1024000000.0, 10.0));
Console.WriteLine(FormatSpeed(100 * 1024 * 1024.0, 10.0));
static string FormatSpeed( double size, double tspan )
string message = "Download Speed: ";
if( size/tspan > 1024 * 1024 )
return string.Format(message + "{0:N1} {1}", size/(1024*1204)/tspan, "MB/s");
}else if( size/tspan > 1024 )
return string.Format(message + "{0:N0} {1}", size/1024/tspan, "KB/s");
return string.Format(message + "{0:N1} {1}", size/1024/tspan, "KB/s");