Here you can find the source of humanReadableByteCount(long bytes, boolean si)
public static String humanReadableByteCount(long bytes, boolean si)
//package com.java2s; //License from project: Open Source License import java.util.Locale; public class Main { public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = ("KMGTPE").charAt(exp - 1) + ""; return String.format(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); }/* w w w . ja v a 2 s . c om*/ }