/// <summary> /// 人类可识别的文件大小显示格式 /// </summary> /// <param name="size">文件大小(Byte为单位)</param> /// <returns></returns> public static string HumanReadableFileSize(double size) { string[] units = new string[] { "B", "KB", "MB", "GB", "TB", "PB" }; double mod = 1024.0; int i = 0; while (size >= mod) { size /= mod; i++; } //四舍六入 //return Math.Round(size) + units[i]; //取小数点后一位 return size.ToString("0.0"); }
时间: 2024-10-13 19:39:14