/// <summary> /// 将数字转换为数据大小格式 /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static string FormatBytesStr(long bytes) { double num; if (bytes > 0x40000000) { num = (double)bytes / 0x40000000; return (num.ToString("N02") + "G"); } if (bytes > 0x100000) { num = (double)bytes / 0x100000; return (num.ToString("N02") + "M"); } if (bytes > 0x400) { num = (double)bytes / 0x400; return (num.ToString("N02") + "K"); } return (bytes.ToString() + "B"); }
以b为单位