C# 转化文件大小

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/My_ben/article/details/83986342

转化文件大小,代码如下:

public static string ConvertFileSize(int fileSize)
{
    string outFileSize = string.Empty;
    if (fileSize < 1024)
    {
        outFileSize = String.Format("{0}B", fileSize);
    }
    else if (fileSize < 1024 * 1024)
    {
         outFileSize = String.Format("{0}KB", fileSize / 1024);
    }
    else if (fileSize < 1024 * 1024 * 1024)
    {
         outFileSize = String.Format("{0}MB", fileSize / (1024 * 1024));
    }
    else
    {
         outFileSize = String.Format("{0}GB", fileSize / (1024 * 1024 * 1024));
    }
    return outFileSize;
}
展开阅读全文

没有更多推荐了,返回首页