标签:mod span 大小 字节流 div size read ret while
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的形式
标签:mod span 大小 字节流 div size read ret while
原文地址:https://www.cnblogs.com/ACDIV/p/10753323.html