Java Utililty Methods Size Format

List of utility methods to do Size Format

Description

The list of methods to do Size Format are organized into topic(s).

Method

StringformatSize(long size)
format Size
NumberFormat formatter = NumberFormat.getInstance();
formatter.setMaximumFractionDigits(1);
formatter.setMinimumFractionDigits(1);
float mbValue = size;
String format;
if (mbValue < 1024) {
    format = formatter.format(mbValue) + " KB";
} else {
...
StringformatSize(long size, boolean forceFixLen, boolean forceSizeInBytes)
format Size
StringBuilder buf = new StringBuilder(64);
appendSizeText(buf, size, forceFixLen, forceSizeInBytes);
return buf.toString();
StringformatSize(long sizeInByte)
Utility method to format a given size in Byte to a human readable format.
if (sizeInByte <= 0) {
    return "0";
final int digitGroups = (int) (Math.log10(sizeInByte) / Math.log10(ONE_KILOBYTE_IN_BYTE));
return FILE_SIZE_FORMAT.format(sizeInByte / Math.pow(ONE_KILOBYTE_IN_BYTE, digitGroups)) + " "
        + FILE_SIZE_UNITS[digitGroups];
StringformatSize(long sizeInBytes)
format Size
double displaySize = sizeInBytes;
int unitIndex;
for (unitIndex = 0; unitIndex < SIZE_NAMES.length; unitIndex++) {
    if (displaySize < 1024) {
        break;
    displaySize = displaySize / 1024.0;
DecimalFormat decimalFormat = new DecimalFormat("#.##");
return decimalFormat.format(displaySize) + SIZE_NAMES[unitIndex];
StringformatSizeInfo(long size)
Get size info
double value = size;
String unit = "Byte(s)";
if (value >= 1024) {
    value /= 1024;
    unit = "KB(s)";
if (value >= 1024) {
    value /= 1024;
...
StringformatStorageSize(Double size, String label)
formatStorageSize Convert a double representation into the label of folder size.
StringBuffer str = new StringBuffer();
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(1);
if (size != null) {
    if (("KB").equals(label)) {
        if (size.doubleValue() < 1024) {
            str.append(nf.format(size.doubleValue())).append(" KB");
...