Here you can find the source of humanReadableByteCount(long bytes, boolean size)
public static String humanReadableByteCount(long bytes, boolean size)
//package com.java2s; public class Main { public static String humanReadableByteCount(long bytes, boolean size) { int unit = size ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; }//w w w. j av a 2 s.co m int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (size ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (size ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } }