C# 常用公共方法
/// <summary> /// 文件大小单位格式(GB/MB/KB/B) /// </summary> /// <param name="b"></param> /// <returns></returns> public static string FileUnitToString(long b) { const double GB = 1024 * 1024 * 1024; const double MB = 1024 * 1024; const double KB = 1024; if (b / GB >= 1) { return Math.Round(b / (double)GB, 1) + "GB"; } if (b / MB >= 1) { return Math.Round(b / (double)MB, 1) + "MB"; } if (b / KB >= 1) { return Math.Round(b / (double)KB, 1) + "KB"; } return b + "B"; }