返回文件大小! 例如:1M
private const double KBCount = 1024;
private const double MBCount = KBCount * 1024;
private const double GBCount = MBCount * 1024;
private const double TBCount = GBCount * 1024;
/// <summary>
/// 得到适应的大小
/// </summary>
/// <param name="path"></param>
/// <returns>string</returns>
public static string GetAutoSizeString(double size,int roundCount)
{
if (KBCount > size)
{
return Math.Round(size, roundCount) + "B";
}
else if (MBCount > size)
{
return Math.Round(size / KBCount, roundCount) + "KB";
}
else if (GBCount > size)
{
return Math.Round(size / MBCount, roundCount) + "MB";
}
else if (TBCount > size)
{
return Math.Round(size / GBCount, roundCount) + "GB";
}
else
{
return Math.Round(size / TBCount, roundCount) + "TB";
}
}