code: public static String formatBytesForDisplay(long amount) {
          double displayAmount = (double) amount;
          int unitPowerOf1024 = 0; 
  
          if(amount <= 0){
              return "0 B";
          }
          
          while(displayAmount>=1024 && unitPowerOf1024 < 4) {
              displayAmount = displayAmount / 1024;
              unitPowerOf1024++;
          }
          
          final String[] units = { " B", " KiB", " MiB", " GiB", " TiB" };
          
          // ensure at least 2 significant digits (#.#) for small displayValues
          int fractionDigits = (displayAmount < 10) ? 1 : 0; 
          return doubleToString(displayAmount, fractionDigits, fractionDigits) 
                     + units[unitPowerOf1024];
      }
docs: Takes a byte size and formats it for display with 'friendly' units.
  <p>
  This involves converting it to the largest unit
  (of B, KiB, MiB, GiB, TiB) for which the amount will be > 1.
  <p>
  Additionally, at least 2 significant digits are always displayed.
  <p>
  Negative numbers will be returned as '0 B'.
  
  @param amount the amount of bytes
  @return A string containing the amount, properly formated.