C# KB转换MB

   public static string GetFileSize(string value)
        {
            if (string.IsNullOrWhiteSpace(value)) return value;
            var size = Convert.ToDouble(value);
            var units = new [] { "B", "KB", "MB", "GB", "TB", "PB" };
            double mod = 1024.0;
            int i = 0;
            while (size >= mod)
            {
                size /= mod;
                i++;
            }
            return size.ToString("0.00") + units[i];

        }

 

posted @ 2021-03-09 12:04  b̶i̶n̶g̶.̶  阅读(185)  评论(0编辑  收藏  举报