Files
netch/Netch/Utils/Bandwidth.cs
Connection Refused b2ea730984 done
2019-12-02 19:51:12 +08:00

25 lines
619 B
C#

namespace Netch.Utils
{
public static class Bandwidth
{
/// <summary>
/// 计算流量
/// </summary>
/// <param name="bandwidth">流量</param>
/// <returns>带单位的流量字符串</returns>
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 System.String.Format("{0} {1}", System.Math.Round(result, 2), units[i]);
}
}
}