code: private String formatNumStr(int bits, String str) {
  
          String ret;
          String[] inputStr = str.split("\\.");
          if (str.trim().equals("")) {
              ret = String.format("%" + bits + "s", "");
          } else if (str.length() <= bits) {
              ret = String.format("%1$" + bits + "s", str);
          } else if (inputStr[0].length() > bits) {
              ret = String.format("%" + bits + "s", str);
          } else {
              int decimalLength = bits - inputStr[0].length() - 1;
              decimalLength = decimalLength < 0 ? 0 : decimalLength;
              ret = org.agmip.common.Functions.round(str, decimalLength);
          }
  
          return ret;
      }
docs: Format the number with maximum length and type
  
  @param bits Maximum length of the output string
  @param str String for number value
  @return formated string of number