private StringBuffer subformat(StringBuffer result,FieldDelegate delegate,boolean isNegative,boolean isInteger,int maxIntDigits,int minIntDigits,int maxFraDigits,int minFraDigits){
  char zero=symbols.getZeroDigit();
  int zeroDelta=zero - '0';
  char grouping=symbols.getGroupingSeparator();
  char decimal=isCurrencyFormat ? symbols.getMonetaryDecimalSeparator() : symbols.getDecimalSeparator();
  if (digitList.isZero()) {
    digitList.decimalAt=0;
  }
  if (isNegative) {
    append(result,negativePrefix,delegate,getNegativePrefixFieldPositions(),Field.SIGN);
  }
 else {
    append(result,positivePrefix,delegate,getPositivePrefixFieldPositions(),Field.SIGN);
  }
  if (useExponentialNotation) {
    int iFieldStart=result.length();
    int iFieldEnd=-1;
    int fFieldStart=-1;
    int exponent=digitList.decimalAt;
    int repeat=maxIntDigits;
    int minimumIntegerDigits=minIntDigits;
    if (repeat > 1 && repeat > minIntDigits) {
      if (exponent >= 1) {
        exponent=((exponent - 1) / repeat) * repeat;
      }
 else {
        exponent=((exponent - repeat) / repeat) * repeat;
      }
      minimumIntegerDigits=1;
    }
 else {
      exponent-=minimumIntegerDigits;
    }
    int minimumDigits=minIntDigits + minFraDigits;
    if (minimumDigits < 0) {
      minimumDigits=Integer.MAX_VALUE;
    }
    int integerDigits=digitList.isZero() ? minimumIntegerDigits : digitList.decimalAt - exponent;
    if (minimumDigits < integerDigits) {
      minimumDigits=integerDigits;
    }
    int totalDigits=digitList.count;
    if (minimumDigits > totalDigits) {
      totalDigits=minimumDigits;
    }
    boolean addedDecimalSeparator=false;
    for (int i=0; i < totalDigits; ++i) {
      if (i == integerDigits) {
        iFieldEnd=result.length();
        result.append(decimal);
        addedDecimalSeparator=true;
        fFieldStart=result.length();
      }
      result.append((i < digitList.count) ? (char)(digitList.digits[i] + zeroDelta) : zero);
    }
    if (decimalSeparatorAlwaysShown && totalDigits == integerDigits) {
      iFieldEnd=result.length();
      result.append(decimal);
      addedDecimalSeparator=true;
      fFieldStart=result.length();
    }
    if (iFieldEnd == -1) {
      iFieldEnd=result.length();
    }
    delegate.formatted(INTEGER_FIELD,Field.INTEGER,Field.INTEGER,iFieldStart,iFieldEnd,result);
    if (addedDecimalSeparator) {
      delegate.formatted(Field.DECIMAL_SEPARATOR,Field.DECIMAL_SEPARATOR,iFieldEnd,fFieldStart,result);
    }
    if (fFieldStart == -1) {
      fFieldStart=result.length();
    }
    delegate.formatted(FRACTION_FIELD,Field.FRACTION,Field.FRACTION,fFieldStart,result.length(),result);
    int fieldStart=result.length();
    result.append(symbols.getExponentSeparator());
    delegate.formatted(Field.EXPONENT_SYMBOL,Field.EXPONENT_SYMBOL,fieldStart,result.length(),result);
    if (digitList.isZero()) {
      exponent=0;
    }
    boolean negativeExponent=exponent < 0;
    if (negativeExponent) {
      exponent=-exponent;
      fieldStart=result.length();
      result.append(symbols.getMinusSign());
      delegate.formatted(Field.EXPONENT_SIGN,Field.EXPONENT_SIGN,fieldStart,result.length(),result);
    }
    digitList.set(negativeExponent,exponent);
    int eFieldStart=result.length();
    for (int i=digitList.decimalAt; i < minExponentDigits; ++i) {
      result.append(zero);
    }
    for (int i=0; i < digitList.decimalAt; ++i) {
      result.append((i < digitList.count) ? (char)(digitList.digits[i] + zeroDelta) : zero);
    }
    delegate.formatted(Field.EXPONENT,Field.EXPONENT,eFieldStart,result.length(),result);
  }
 else {
    int iFieldStart=result.length();
    int count=minIntDigits;
    int digitIndex=0;
    if (digitList.decimalAt > 0 && count < digitList.decimalAt) {
      count=digitList.decimalAt;
    }
    if (count > maxIntDigits) {
      count=maxIntDigits;
      digitIndex=digitList.decimalAt - count;
    }
    int sizeBeforeIntegerPart=result.length();
    for (int i=count - 1; i >= 0; --i) {
      if (i < digitList.decimalAt && digitIndex < digitList.count) {
        result.append((char)(digitList.digits[digitIndex++] + zeroDelta));
      }
 else {
        result.append(zero);
      }
      if (isGroupingUsed() && i > 0 && (groupingSize != 0) && (i % groupingSize == 0)) {
        int gStart=result.length();
        result.append(grouping);
        delegate.formatted(Field.GROUPING_SEPARATOR,Field.GROUPING_SEPARATOR,gStart,result.length(),result);
      }
    }
    boolean fractionPresent=(minFraDigits > 0) || (!isInteger && digitIndex < digitList.count);
    if (!fractionPresent && result.length() == sizeBeforeIntegerPart) {
      result.append(zero);
    }
    delegate.formatted(INTEGER_FIELD,Field.INTEGER,Field.INTEGER,iFieldStart,result.length(),result);
    int sStart=result.length();
    if (decimalSeparatorAlwaysShown || fractionPresent) {
      result.append(decimal);
    }
    if (sStart != result.length()) {
      delegate.formatted(Field.DECIMAL_SEPARATOR,Field.DECIMAL_SEPARATOR,sStart,result.length(),result);
    }
    int fFieldStart=result.length();
    for (int i=0; i < maxFraDigits; ++i) {
      if (i >= minFraDigits && (isInteger || digitIndex >= digitList.count)) {
        break;
      }
      if (-1 - i > (digitList.decimalAt - 1)) {
        result.append(zero);
        continue;
      }
      if (!isInteger && digitIndex < digitList.count) {
        result.append((char)(digitList.digits[digitIndex++] + zeroDelta));
      }
 else {
        result.append(zero);
      }
    }
    delegate.formatted(FRACTION_FIELD,Field.FRACTION,Field.FRACTION,fFieldStart,result.length(),result);
  }
  if (isNegative) {
    append(result,negativeSuffix,delegate,getNegativeSuffixFieldPositions(),Field.SIGN);
  }
 else {
    append(result,positiveSuffix,delegate,getPositiveSuffixFieldPositions(),Field.SIGN);
  }
  return result;
}

private StringBuffer subformat ( StringBuffer result , FieldDelegate delegate , boolean isNegative , boolean isInteger , int maxIntDigits , int minIntDigits , int maxFraDigits , int minFraDigits ) { char zero = symbols . getZeroDigit ( ) ; int zeroDelta = zero - '0' ; char grouping = symbols . getGroupingSeparator ( ) ; char decimal = isCurrencyFormat ? symbols . getMonetaryDecimalSeparator ( ) : symbols . getDecimalSeparator ( ) ; if ( digitList . isZero ( ) ) { digitList . decimalAt = 0 ; } if ( isNegative ) { append ( result , negativePrefix , delegate , getNegativePrefixFieldPositions ( ) , Field . SIGN ) ; } else { append ( result , positivePrefix , delegate , getPositivePrefixFieldPositions ( ) , Field . SIGN ) ; } if ( useExponentialNotation ) { int iFieldStart = result . length ( ) ; int iFieldEnd = - 1 ; int fFieldStart = - 1 ; int exponent = digitList . decimalAt ; int repeat = maxIntDigits ; int minimumIntegerDigits = minIntDigits ; if ( repeat > 1 && repeat > minIntDigits ) { if ( exponent >= 1 ) { exponent = ( ( exponent - 1 ) / repeat ) * repeat ; } else { exponent = ( ( exponent - repeat ) / repeat ) * repeat ; } minimumIntegerDigits = 1 ; } else { exponent -= minimumIntegerDigits ; } int minimumDigits = minIntDigits + minFraDigits ; if ( minimumDigits < 0 ) { minimumDigits = Integer . MAX_VALUE ; } int integerDigits = digitList . isZero ( ) ? minimumIntegerDigits : digitList . decimalAt - exponent ; if ( minimumDigits < integerDigits ) { minimumDigits = integerDigits ; } int totalDigits = digitList . count ; if ( minimumDigits > totalDigits ) { totalDigits = minimumDigits ; } boolean addedDecimalSeparator = false ; for ( int i = 0 ; i < totalDigits ; ++ i ) { if ( i == integerDigits ) { iFieldEnd = result . length ( ) ; result . append ( decimal ) ; addedDecimalSeparator = true ; fFieldStart = result . length ( ) ; } result . append ( ( i < digitList . count ) ? ( char ) ( digitList . digits [ i ] + zeroDelta ) : zero ) ; } if ( decimalSeparatorAlwaysShown && totalDigits == integerDigits ) { iFieldEnd = result . length ( ) ; result . append ( decimal ) ; addedDecimalSeparator = true ; fFieldStart = result . length ( ) ; } if ( iFieldEnd == - 1 ) { iFieldEnd = result . length ( ) ; } delegate . formatted ( INTEGER_FIELD , Field . INTEGER , Field . INTEGER , iFieldStart , iFieldEnd , result ) ; if ( addedDecimalSeparator ) { delegate . formatted ( Field . DECIMAL_SEPARATOR , Field . DECIMAL_SEPARATOR , iFieldEnd , fFieldStart , result ) ; } if ( fFieldStart == - 1 ) { fFieldStart = result . length ( ) ; } delegate . formatted ( FRACTION_FIELD , Field . FRACTION , Field . FRACTION , fFieldStart , result . length ( ) , result ) ; int fieldStart = result . length ( ) ; result . append ( symbols . getExponentSeparator ( ) ) ; delegate . formatted ( Field . EXPONENT_SYMBOL , Field . EXPONENT_SYMBOL , fieldStart , result . length ( ) , result ) ; if ( digitList . isZero ( ) ) { exponent = 0 ; } boolean negativeExponent = exponent < 0 ; if ( negativeExponent ) { exponent = - exponent ; fieldStart = result . length ( ) ; result . append ( symbols . getMinusSign ( ) ) ; delegate . formatted ( Field . EXPONENT_SIGN , Field . EXPONENT_SIGN , fieldStart , result . length ( ) , result ) ; } digitList . set ( negativeExponent , exponent ) ; int eFieldStart = result . length ( ) ; for ( int i = digitList . decimalAt ; i < minExponentDigits ; ++ i ) { result . append ( zero ) ; } for ( int i = 0 ; i < digitList . decimalAt ; ++ i ) { result . append ( ( i < digitList . count ) ? ( char ) ( digitList . digits [ i ] + zeroDelta ) : zero ) ; } delegate . formatted ( Field . EXPONENT , Field . EXPONENT , eFieldStart , result . length ( ) , result ) ; } else { int iFieldStart = result . length ( ) ; int count = minIntDigits ; int digitIndex = 0 ; if ( digitList . decimalAt > 0 && count < digitList . decimalAt ) { count = digitList . decimalAt ; } if ( count > maxIntDigits ) { count = maxIntDigits ; digitIndex = digitList . decimalAt - count ; } int sizeBeforeIntegerPart = result . length ( ) ; for ( int i = count - 1 ; i >= 0 ; -- i ) { if ( i < digitList . decimalAt && digitIndex < digitList . count ) { result . append ( ( char ) ( digitList . digits [ digitIndex ++ ] + zeroDelta ) ) ; } else { result . append ( zero ) ; } if ( isGroupingUsed ( ) && i > 0 && ( groupingSize != 0 ) && ( i % groupingSize == 0 ) ) { int gStart = result . length ( ) ; result . append ( grouping ) ; delegate . formatted ( Field . GROUPING_SEPARATOR , Field . GROUPING_SEPARATOR , gStart , result . length ( ) , result ) ; } } boolean fractionPresent = ( minFraDigits > 0 ) || ( ! isInteger && digitIndex < digitList . count ) ; if ( ! fractionPresent && result . length ( ) == sizeBeforeIntegerPart ) { result . append ( zero ) ; } delegate . formatted ( INTEGER_FIELD , Field . INTEGER , Field . INTEGER , iFieldStart , result . length ( ) , result ) ; int sStart = result . length ( ) ; if ( decimalSeparatorAlwaysShown || fractionPresent ) { result . append ( decimal ) ; } if ( sStart != result . length ( ) ) { delegate . formatted ( Field . DECIMAL_SEPARATOR , Field . DECIMAL_SEPARATOR , sStart , result . length ( ) , result ) ; } int fFieldStart = result . length ( ) ; for ( int i = 0 ; i < maxFraDigits ; ++ i ) { if ( i >= minFraDigits && ( isInteger || digitIndex >= digitList . count ) ) { break ; } if ( - 1 - i > ( digitList . decimalAt - 1 ) ) { result . append ( zero ) ; continue ; } if ( ! isInteger && digitIndex < digitList . count ) { result . append ( ( char ) ( digitList . digits [ digitIndex ++ ] + zeroDelta ) ) ; } else { result . append ( zero ) ; } } delegate . formatted ( FRACTION_FIELD , Field . FRACTION , Field . FRACTION , fFieldStart , result . length ( ) , result ) ; } if ( isNegative ) { append ( result , negativeSuffix , delegate , getNegativeSuffixFieldPositions ( ) , Field . SIGN ) ; } else { append ( result , positiveSuffix , delegate , getPositiveSuffixFieldPositions ( ) , Field . SIGN ) ; } return result ; }
complete the formatting of a finite number . on entry , the digitlist must be filled in with the correct digits .
