Here you can find the source of humanReadableByteCount(BigDecimal bytes, Boolean si)
public static String humanReadableByteCount(BigDecimal bytes, Boolean si)
//package com.java2s; import java.math.BigDecimal; public class Main { public static String humanReadableByteCount(double bytes) { return humanReadableByteCount(bytes, false); }/*from ww w.j a v a2 s . c om*/ public static String humanReadableByteCount(double bytes, boolean internationalSystemOfUnits) { int unit = internationalSystemOfUnits ? 1000 : 1024; if (bytes <= 0) { return "0"; // default units for zero value } else if (bytes < unit) { return bytes + " B"; } int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (internationalSystemOfUnits ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + ""; return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } public static String humanReadableByteCount(BigDecimal bytes, Boolean si) { return humanReadableByteCount(bytes.doubleValue(), si); } }