private char[] fFormatDigits(final double x){
  String sx;
  int i, j, k;
  final int n1In;
  final int n2In;
  int expon=0;
  boolean minusSign=false;
  if (x > 0.0) {
    sx=Double.toString(x);
  }
 else   if (x < 0.0) {
    sx=Double.toString(-x);
    minusSign=true;
  }
 else {
    sx=Double.toString(x);
    if (sx.charAt(0) == '-') {
      minusSign=true;
      sx=sx.substring(1);
    }
  }
  final int ePos=sx.indexOf('E');
  final int rPos=sx.indexOf('.');
  if (rPos != -1) {
    n1In=rPos;
  }
 else   if (ePos != -1) {
    n1In=ePos;
  }
 else {
    n1In=sx.length();
  }
  if (rPos != -1) {
    if (ePos != -1) {
      n2In=ePos - rPos - 1;
    }
 else {
      n2In=sx.length() - rPos - 1;
    }
  }
 else {
    n2In=0;
  }
  if (ePos != -1) {
    int ie=ePos + 1;
    expon=0;
    if (sx.charAt(ie) == '-') {
      for (++ie; ie < sx.length(); ie++) {
        if (sx.charAt(ie) != '0') {
          break;
        }
      }
      if (ie < sx.length()) {
        expon=-Integer.parseInt(sx.substring(ie));
      }
    }
 else {
      if (sx.charAt(ie) == '+') {
        ++ie;
      }
      for (; ie < sx.length(); ie++) {
        if (sx.charAt(ie) != '0') {
          break;
        }
      }
      if (ie < sx.length()) {
        expon=Integer.parseInt(sx.substring(ie));
      }
    }
  }
  final int p;
  if (precisionSet) {
    p=precision;
  }
 else {
    p=defaultDigits - 1;
  }
  final char[] ca1=sx.toCharArray();
  final char[] ca2=new char[n1In + n2In];
  final char[] ca3;
  final char[] ca4;
  final char[] ca5;
  for (j=0; j < n1In; j++) {
    ca2[j]=ca1[j];
  }
  i=j + 1;
  for (k=0; k < n2In; j++, i++, k++) {
    ca2[j]=ca1[i];
  }
  if (n1In + expon <= 0) {
    ca3=new char[-expon + n2In];
    for (j=0, k=0; k < (-n1In - expon); k++, j++) {
      ca3[j]='0';
    }
    for (i=0; i < (n1In + n2In); i++, j++) {
      ca3[j]=ca2[i];
    }
  }
 else {
    ca3=ca2;
  }
  boolean carry=false;
  if (p < -expon + n2In) {
    if (expon < 0) {
      i=p;
    }
 else {
      i=p + n1In;
    }
    carry=checkForCarry(ca3,i);
    if (carry) {
      carry=startSymbolicCarry(ca3,i - 1,0);
    }
  }
  if (n1In + expon <= 0) {
    ca4=new char[2 + p];
    if (!carry) {
      ca4[0]='0';
    }
 else {
      ca4[0]='1';
    }
    if (alternateForm || !precisionSet || precision != 0) {
      ca4[1]='.';
      for (i=0, j=2; i < Math.min(p,ca3.length); i++, j++) {
        ca4[j]=ca3[i];
      }
      for (; j < ca4.length; j++) {
        ca4[j]='0';
      }
    }
  }
 else {
    if (!carry) {
      if (alternateForm || !precisionSet || precision != 0) {
        ca4=new char[n1In + expon + p+ 1];
      }
 else {
        ca4=new char[n1In + expon];
      }
      j=0;
    }
 else {
      if (alternateForm || !precisionSet || precision != 0) {
        ca4=new char[n1In + expon + p+ 2];
      }
 else {
        ca4=new char[n1In + expon + 1];
      }
      ca4[0]='1';
      j=1;
    }
    for (i=0; i < Math.min(n1In + expon,ca3.length); i++, j++) {
      ca4[j]=ca3[i];
    }
    for (; i < n1In + expon; i++, j++) {
      ca4[j]='0';
    }
    if (alternateForm || !precisionSet || precision != 0) {
      ca4[j]='.';
      j++;
      for (k=0; i < ca3.length && k < p; i++, j++, k++) {
        ca4[j]=ca3[i];
      }
      for (; j < ca4.length; j++) {
        ca4[j]='0';
      }
    }
  }
  int nZeros=0;
  if (!leftJustify && leadingZeros) {
    int xThousands=0;
    if (thousands) {
      int xlead=0;
      if (ca4[0] == '+' || ca4[0] == '-' || ca4[0] == ' ') {
        xlead=1;
      }
      int xdp=xlead;
      for (; xdp < ca4.length; xdp++) {
        if (ca4[xdp] == '.') {
          break;
        }
      }
      xThousands=(xdp - xlead) / 3;
    }
    if (fieldWidthSet) {
      nZeros=fieldWidth - ca4.length;
    }
    if ((!minusSign && (leadingSign || leadingSpace)) || minusSign) {
      nZeros--;
    }
    nZeros-=xThousands;
    if (nZeros < 0) {
      nZeros=0;
    }
  }
  j=0;
  if ((!minusSign && (leadingSign || leadingSpace)) || minusSign) {
    ca5=new char[ca4.length + nZeros + 1];
    j++;
  }
 else {
    ca5=new char[ca4.length + nZeros];
  }
  if (!minusSign) {
    if (leadingSign) {
      ca5[0]='+';
    }
    if (leadingSpace) {
      ca5[0]=' ';
    }
  }
 else {
    ca5[0]='-';
  }
  for (i=0; i < nZeros; i++, j++) {
    ca5[j]='0';
  }
  for (i=0; i < ca4.length; i++, j++) {
    ca5[j]=ca4[i];
  }
  int lead=0;
  if (ca5[0] == '+' || ca5[0] == '-' || ca5[0] == ' ') {
    lead=1;
  }
  int dp=lead;
  for (; dp < ca5.length; dp++) {
    if (ca5[dp] == '.') {
      break;
    }
  }
  final int nThousands=(dp - lead) / 3;
  if (dp < ca5.length) {
    ca5[dp]=dfs.getDecimalSeparator();
  }
  char[] ca6=ca5;
  if (thousands && nThousands > 0) {
    ca6=new char[ca5.length + nThousands + lead];
    ca6[0]=ca5[0];
    for (i=lead, k=lead; i < dp; i++) {
      if (i > 0 && (dp - i) % 3 == 0) {
        ca6[k]=dfs.getGroupingSeparator();
        ca6[k + 1]=ca5[i];
        k+=2;
      }
 else {
        ca6[k]=ca5[i];
        k++;
      }
    }
    for (; i < ca5.length; i++, k++) {
      ca6[k]=ca5[i];
    }
  }
  return ca6;
}

private char [ ] fFormatDigits ( final double x ) { String sx ; int i , j , k ; final int n1In ; final int n2In ; int expon = 0 ; boolean minusSign = false ; if ( x > 0.0 ) { sx = Double . toString ( x ) ; } else if ( x < 0.0 ) { sx = Double . toString ( - x ) ; minusSign = true ; } else { sx = Double . toString ( x ) ; if ( sx . charAt ( 0 ) == '-' ) { minusSign = true ; sx = sx . substring ( 1 ) ; } } final int ePos = sx . indexOf ( 'E' ) ; final int rPos = sx . indexOf ( '.' ) ; if ( rPos != - 1 ) { n1In = rPos ; } else if ( ePos != - 1 ) { n1In = ePos ; } else { n1In = sx . length ( ) ; } if ( rPos != - 1 ) { if ( ePos != - 1 ) { n2In = ePos - rPos - 1 ; } else { n2In = sx . length ( ) - rPos - 1 ; } } else { n2In = 0 ; } if ( ePos != - 1 ) { int ie = ePos + 1 ; expon = 0 ; if ( sx . charAt ( ie ) == '-' ) { for ( ++ ie ; ie < sx . length ( ) ; ie ++ ) { if ( sx . charAt ( ie ) != '0' ) { break ; } } if ( ie < sx . length ( ) ) { expon = - Integer . parseInt ( sx . substring ( ie ) ) ; } } else { if ( sx . charAt ( ie ) == '+' ) { ++ ie ; } for ( ; ie < sx . length ( ) ; ie ++ ) { if ( sx . charAt ( ie ) != '0' ) { break ; } } if ( ie < sx . length ( ) ) { expon = Integer . parseInt ( sx . substring ( ie ) ) ; } } } final int p ; if ( precisionSet ) { p = precision ; } else { p = defaultDigits - 1 ; } final char [ ] ca1 = sx . toCharArray ( ) ; final char [ ] ca2 = new char [ n1In + n2In ] ; final char [ ] ca3 ; final char [ ] ca4 ; final char [ ] ca5 ; for ( j = 0 ; j < n1In ; j ++ ) { ca2 [ j ] = ca1 [ j ] ; } i = j + 1 ; for ( k = 0 ; k < n2In ; j ++ , i ++ , k ++ ) { ca2 [ j ] = ca1 [ i ] ; } if ( n1In + expon <= 0 ) { ca3 = new char [ - expon + n2In ] ; for ( j = 0 , k = 0 ; k < ( - n1In - expon ) ; k ++ , j ++ ) { ca3 [ j ] = '0' ; } for ( i = 0 ; i < ( n1In + n2In ) ; i ++ , j ++ ) { ca3 [ j ] = ca2 [ i ] ; } } else { ca3 = ca2 ; } boolean carry = false ; if ( p < - expon + n2In ) { if ( expon < 0 ) { i = p ; } else { i = p + n1In ; } carry = checkForCarry ( ca3 , i ) ; if ( carry ) { carry = startSymbolicCarry ( ca3 , i - 1 , 0 ) ; } } if ( n1In + expon <= 0 ) { ca4 = new char [ 2 + p ] ; if ( ! carry ) { ca4 [ 0 ] = '0' ; } else { ca4 [ 0 ] = '1' ; } if ( alternateForm || ! precisionSet || precision != 0 ) { ca4 [ 1 ] = '.' ; for ( i = 0 , j = 2 ; i < Math . min ( p , ca3 . length ) ; i ++ , j ++ ) { ca4 [ j ] = ca3 [ i ] ; } for ( ; j < ca4 . length ; j ++ ) { ca4 [ j ] = '0' ; } } } else { if ( ! carry ) { if ( alternateForm || ! precisionSet || precision != 0 ) { ca4 = new char [ n1In + expon + p + 1 ] ; } else { ca4 = new char [ n1In + expon ] ; } j = 0 ; } else { if ( alternateForm || ! precisionSet || precision != 0 ) { ca4 = new char [ n1In + expon + p + 2 ] ; } else { ca4 = new char [ n1In + expon + 1 ] ; } ca4 [ 0 ] = '1' ; j = 1 ; } for ( i = 0 ; i < Math . min ( n1In + expon , ca3 . length ) ; i ++ , j ++ ) { ca4 [ j ] = ca3 [ i ] ; } for ( ; i < n1In + expon ; i ++ , j ++ ) { ca4 [ j ] = '0' ; } if ( alternateForm || ! precisionSet || precision != 0 ) { ca4 [ j ] = '.' ; j ++ ; for ( k = 0 ; i < ca3 . length && k < p ; i ++ , j ++ , k ++ ) { ca4 [ j ] = ca3 [ i ] ; } for ( ; j < ca4 . length ; j ++ ) { ca4 [ j ] = '0' ; } } } int nZeros = 0 ; if ( ! leftJustify && leadingZeros ) { int xThousands = 0 ; if ( thousands ) { int xlead = 0 ; if ( ca4 [ 0 ] == '+' || ca4 [ 0 ] == '-' || ca4 [ 0 ] == ' ' ) { xlead = 1 ; } int xdp = xlead ; for ( ; xdp < ca4 . length ; xdp ++ ) { if ( ca4 [ xdp ] == '.' ) { break ; } } xThousands = ( xdp - xlead ) / 3 ; } if ( fieldWidthSet ) { nZeros = fieldWidth - ca4 . length ; } if ( ( ! minusSign && ( leadingSign || leadingSpace ) ) || minusSign ) { nZeros -- ; } nZeros -= xThousands ; if ( nZeros < 0 ) { nZeros = 0 ; } } j = 0 ; if ( ( ! minusSign && ( leadingSign || leadingSpace ) ) || minusSign ) { ca5 = new char [ ca4 . length + nZeros + 1 ] ; j ++ ; } else { ca5 = new char [ ca4 . length + nZeros ] ; } if ( ! minusSign ) { if ( leadingSign ) { ca5 [ 0 ] = '+' ; } if ( leadingSpace ) { ca5 [ 0 ] = ' ' ; } } else { ca5 [ 0 ] = '-' ; } for ( i = 0 ; i < nZeros ; i ++ , j ++ ) { ca5 [ j ] = '0' ; } for ( i = 0 ; i < ca4 . length ; i ++ , j ++ ) { ca5 [ j ] = ca4 [ i ] ; } int lead = 0 ; if ( ca5 [ 0 ] == '+' || ca5 [ 0 ] == '-' || ca5 [ 0 ] == ' ' ) { lead = 1 ; } int dp = lead ; for ( ; dp < ca5 . length ; dp ++ ) { if ( ca5 [ dp ] == '.' ) { break ; } } final int nThousands = ( dp - lead ) / 3 ; if ( dp < ca5 . length ) { ca5 [ dp ] = dfs . getDecimalSeparator ( ) ; } char [ ] ca6 = ca5 ; if ( thousands && nThousands > 0 ) { ca6 = new char [ ca5 . length + nThousands + lead ] ; ca6 [ 0 ] = ca5 [ 0 ] ; for ( i = lead , k = lead ; i < dp ; i ++ ) { if ( i > 0 && ( dp - i ) % 3 == 0 ) { ca6 [ k ] = dfs . getGroupingSeparator ( ) ; ca6 [ k + 1 ] = ca5 [ i ] ; k += 2 ; } else { ca6 [ k ] = ca5 [ i ] ; k ++ ; } } for ( ; i < ca5 . length ; i ++ , k ++ ) { ca6 [ k ] = ca5 [ i ] ; } } return ca6 ; }
for f format , the flag character ' - ' , means that the output should be left justified within the field . the default is to pad with blanks on the left . ' + ' character means that the conversion will always begin with a sign ( + or - ) . the blank flag character means that a non - negative input will be preceded with a blank . if both a ' + ' and a ' ' are specified , the blank flag is ignored . the ' 0 ' flag character implies that padding to the field width will be done with zeros instead of blanks . the field width is treated as the minimum number of characters to be printed . the default is to add no padding . padding is with blanks by default . the precision , if set , is the number of digits to appear after the radix character . padding is with trailing 0s .
