分割字节流为G,MB,KB的算法
String HumanReadableFilesize(double size) { var units = new[] { "B", "KB", "MB", "GB", "TB", "PB" }; double mod = 1024.0; var DoubleCount = new List<double>(); while (size >= mod) { size /= mod; DoubleCount.Add(size); } var Ret = ""; for (int j = DoubleCount.Count; j > 0; j--) { if (j == DoubleCount.Count) { Ret += $"{Math.Floor(DoubleCount[j - 1])}{units[j]}"; } else { Ret += $"{Math.Floor(DoubleCount[j - 1] - (Math.Floor(DoubleCount[j]) * 1024))}{units[j]}"; } } return Ret; }
将字节流大小转换成类似于XXGBXXMBXXKB的形式