List of utility methods to do File Size Readable Format
String | convertFileSize(double size, Locale locale) convert File Size String strSize; long kb = 1024; long mb = 1024 * kb; long gb = 1024 * mb; long tb = 1024 * gb; NumberFormat formatter = NumberFormat.getNumberInstance(locale); formatter.setMaximumFractionDigits(2); formatter.setMinimumFractionDigits(2); ... |
String | convertFileSize(long size) convert File Size long kb = 1024; long mb = kb * 1024; long gb = mb * 1024; DecimalFormat df = new DecimalFormat("#.00"); if (size >= gb) { return df.format((double) size / gb) + "GB"; } else if (size >= mb) { return df.format((double) size / mb) + "MB"; ... |
String | convertFileSize(long size) convert File Size String unit = "B"; if (size >= 1024) { size = size / 1024; unit = "KB"; if (size >= 1024) { size = size / 1024; unit = "MB"; ... |
String | formatarNumeroComZerosAEsquerda(long numero, int size) formatar Numero Com Zeros A Esquerda String result = String.valueOf(numero); while (result.length() < size) { result = "0" + result; return result; |
String | formatByteSize(long bytes, int decimals) format Byte Size decimals = Math.min(Math.max(decimals, 0), 4); if (bytes < 1024) return bytes + "B"; int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = "KMGTPE".charAt(exp - 1) + ""; return String.format("%." + decimals + "f%s", bytes / Math.pow(1024, exp), pre); |
String | formatByteSize(long bytes, int lastDigits) This methode formats the bytes in human readable form. String formated = null; double work = bytes; long count = 0; while (work >= 1024) { work /= 1024; count++; formated = String.valueOf(work); ... |
String | formatByteSize(long byteSize) format Byte Size float size = (float) byteSize; String metrics = " b"; if (size >= 1024) { size = size / 1024; metrics = " Kb"; if (size >= 1024) { size = size / 1024; ... |
String | formatByteSizeToString(long bytes) Present a size (in bytes) as a human-readable value int total = sizes.length - 1; double value = bytes; for (; value > 1024; total--) { value /= 1024; value = (double) ((int) (value * 10)) / 10; return value + " " + sizes[total]; |
String | formatDataSize(long size) Formats the data size in B, KB, MB or GB, TB as needed double dsize = size; String retval = ""; if (dsize < 1024.0) { retval = size + " B"; return retval; if (dsize < 1024.0 * 1024.0) { double val = Math.round(dsize / 1024.0 * 10.0) / 10.0; ... |
String | FormatDataSize(long uBytes) Format Data Size final long uKB = 1024; final long uMB = uKB * uKB; final long uGB = uMB * uKB; final long uTB = uGB * uKB; if (uBytes == 0) return "0 KB"; if (uBytes <= uKB) return "1 KB"; ... |