文件大小

来源:互联网 发布:上海民族乐器一厂 淘宝 编辑:程序博客网 时间:2024/05/17 01:31
    public static string humanReadableByteCount(long bytes)    {        int unit = 1024;        if (bytes < unit) return bytes + " B";        int exp = (int)(Math.Log(bytes) / Math.Log(unit));        return String.Format("{0:F1} {1}B", bytes / Math.Pow(unit, exp), "KMGTPE"[exp - 1]);    }

将Byte数转为其他单位,如多少KB,MB等

long 1024;

humanReadableByteCount(t);

output:1.0 KB

转自:http://www.cnblogs.com/mgen/archive/2012/01/30/2332161.html

原创粉丝点击