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