namespace Netch.Utils
{
public static class Bandwidth
{
///
/// 计算流量
///
/// 流量
/// 带单位的流量字符串
public static string Compute(long bandwidth)
{
string[] units = { "KB", "MB", "GB", "TB", "PB" };
double result = bandwidth;
var i = -1;
do
{
i++;
} while ((result /= 1024) > 1024);
return string.Format("{0} {1}", System.Math.Round(result, 2), units[i]);
}
}
}