Here you can find the source of humanReadableUnits(double bytes, boolean internationalSystemOfUnits)
public static String humanReadableUnits(double bytes, boolean internationalSystemOfUnits)
//package com.java2s; public class Main { public static String humanReadableUnits(double bytes, boolean internationalSystemOfUnits) { int unit = internationalSystemOfUnits ? 1000 : 1024; if (bytes <= 0) { return ""; // default units for zero value } else if (bytes < unit) { return "B"; }//from w w w . j a v a2 s . c o m int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (internationalSystemOfUnits ? "kMGTPEZY" : "KMGTPEZY").charAt(exp - 1) + ""; return String.format("%sB", pre); } }