文件大小

    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

posted @ 2012-09-18 22:52  gitran  阅读(155)  评论(0编辑  收藏  举报