String (long fileSize) { int rank = (int)((Math.log10(fileSize) + 0.0000021714778384307465) / 3); // (3 - Math.log10(999.995)) double value = fileSize / Math.pow(1000, rank); String[] units = {"Bit", "Kbit", "Mbit", "Gbit"}; return new DecimalFormat("0.##").format(value) + units[rank] + "/s"; }