Java BigDecimal humanReadableByteCount(BigDecimal bytes, Boolean si)

Here you can find the source of humanReadableByteCount(BigDecimal bytes, Boolean si)

Description

human Readable Byte Count

License

Open Source License

Declaration

public static String humanReadableByteCount(BigDecimal bytes, Boolean si) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {
    public static String humanReadableByteCount(double bytes) {
        return humanReadableByteCount(bytes, false);
    }/*from  ww w.j a  v  a2 s  . c om*/

    public static String humanReadableByteCount(double bytes, boolean internationalSystemOfUnits) {
        int unit = internationalSystemOfUnits ? 1000 : 1024;
        if (bytes <= 0) {
            return "0"; // default units for zero value
        } else if (bytes < unit) {
            return bytes + " B";
        }
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (internationalSystemOfUnits ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + "";
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }

    public static String humanReadableByteCount(BigDecimal bytes, Boolean si) {
        return humanReadableByteCount(bytes.doubleValue(), si);
    }
}

Related

  1. getValue(String key, Map valuesMap)
  2. getWithoutTrailingZeroes(@Nullable final BigDecimal aValue)
  3. hash(BigDecimal bd)
  4. hasSignedChanged(final BigDecimal v1, final BigDecimal v2)
  5. htmlFooter(String providerNo, int count, BigDecimal total)
  6. incRatio(BigDecimal o1, BigDecimal o2)
  7. intToBigDecimal(int i)
  8. intValue(BigDecimal a)
  9. inverse(final BigDecimal amount)