String (long fileSize, @NotNull String unitSeparator, int rank) { if (fileSize < 0) throw new IllegalArgumentException("Invalid value: " + fileSize); if (fileSize == 0) return '0' + unitSeparator + 'B'; if (rank < 0) { rank = rankForFileSize(fileSize); } double value = fileSize / Math.pow(1000, rank); String[] units = {"B", "kB", "MB", "GB", "TB", "PB", "EB"}; return new DecimalFormat("0.##").format(value) + unitSeparator + units[rank]; }