code: private Number parseInt(String text,
                              int maxDigits,
                              ParsePosition pos,
                              boolean allowNegative,
                              NumberFormat fmt) {
          Number number;
          int oldPos = pos.getIndex();
          if (allowNegative) {
              number = fmt.parse(text, pos);
          } else {
              // Invalidate negative numbers
              if (fmt instanceof DecimalFormat) {
                  String oldPrefix = ((DecimalFormat)fmt).getNegativePrefix();
                  ((DecimalFormat)fmt).setNegativePrefix(SUPPRESS_NEGATIVE_PREFIX);
                  number = fmt.parse(text, pos);
                  ((DecimalFormat)fmt).setNegativePrefix(oldPrefix);
              } else {
                  boolean dateNumberFormat = (fmt instanceof DateNumberFormat);
                  if (dateNumberFormat) {
                      ((DateNumberFormat)fmt).setParsePositiveOnly(true);
                  }
                  number = fmt.parse(text, pos);
                  if (dateNumberFormat) {
                      ((DateNumberFormat)fmt).setParsePositiveOnly(false);
                  }
              }
          }
          if (maxDigits > 0) {
              // adjust the result to fit into
              // the maxDigits and move the position back
              int nDigits = pos.getIndex() - oldPos;
              if (nDigits > maxDigits) {
                  double val = number.doubleValue();
                  nDigits -= maxDigits;
                  while (nDigits > 0) {
                      val /= 10;
                      nDigits--;
                  }
                  pos.setIndex(oldPos + maxDigits);
                  number = Integer.valueOf((int)val);
              }
          }
          return number;
      }
docs: Parse an integer using numberFormat up to maxDigits.