public static String formatSizeInBytes(long bytes, String postfix) {
    String out; 
    if (bytes == 1) {
      out = bytes + " byte";
    }
    else if (bytes < 1024) {
      out = bytes + " bytes";
    }
    else if (bytes < 1024 * 1024) {
      out = String.format("%.1f", ((float)bytes)/1024) + " KB";
    }
    else if (bytes < 1024 * 1024 * 1024) {
      out = String.format("%.1f", ((float)bytes)/(1024 * 1024)) + " MB";
    }
    else {
      out = String.format("%.1f", ((float)bytes)/(1024 * 1024 * 1024)) + " GB";
    }
    if (postfix != null && !postfix.isEmpty()) {
      out += postfix;
    }
    return out;
  }
Format size value specified in bytes
hplsql/src/main/java/org/apache/hive/hplsql/Utils.java