Files
netch/Netch/Utils/Bandwidth.cs
Bruce Wayne 087f6e4eb9 Cleanup code
2020-01-23 20:44:17 +08:00

25 lines
612 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 string.Format("{0} {1}", System.Math.Round(result, 2), units[i]);
}
}
}