code: public static String byteCountToDisplaySize(BigInteger size, int maxChars) {
          String displaySize;
          BigDecimal bdSize = new BigDecimal(size);
          SizeSuffix selectedSuffix = SizeSuffix.B;
          for (SizeSuffix sizeSuffix : SizeSuffix.values()) {
              if (sizeSuffix.equals(SizeSuffix.B)) {
                  continue;
              }
              if (bdSize.setScale(0, RoundingMode.HALF_UP).toString().length() <= maxChars) {
                  break;
              }
              selectedSuffix = sizeSuffix;
              bdSize = bdSize.divide(ONE_KB_BD);
          }
          displaySize = bdSize.setScale(0, RoundingMode.HALF_UP).toString();
          if (displaySize.length() < maxChars - 1) {
              displaySize = bdSize.setScale(
                      maxChars - 1 - displaySize.length(), RoundingMode.HALF_UP).toString();
          }
          return displaySize + " " + selectedSuffix.toString();
      }
docs: Adopted and improved version of
  {@link org.apache.commons.io.FileUtils#byteCountToDisplaySize(BigInteger)}.
  <p>
  Warning! it is not advised to use <code>maxChars &lt; 3</code> because it produces
  correctly rounded, but non-intuitive results like "0 KB" for 100 bytes.
  
  @param size a {@link java.math.BigInteger} object.
  @param maxChars maximum length of digit part, ie. '1.2'
  @return rounded byte size as {@link java.lang.String}