question: private String printDFormat ( String sx ) { int nLeadingZeros = 0 ; int nBlanks = 0 , n = 0 ; int i = 0 ; final int jFirst ; final boolean neg = sx . charAt ( 0 ) == '-' ; if ( sx . equals ( "0" ) && precisionSet && precision == 0 ) { sx = "" ; } if ( ! neg ) { if ( precisionSet && sx . length ( ) < precision ) { nLeadingZeros = precision - sx . length ( ) ; } } else { if ( precisionSet && ( sx . length ( ) - 1 ) < precision ) { nLeadingZeros = precision - sx . length ( ) + 1 ; } } if ( nLeadingZeros < 0 ) { nLeadingZeros = 0 ; } if ( fieldWidthSet ) { nBlanks = fieldWidth - nLeadingZeros - sx . length ( ) ; if ( ! neg && ( leadingSign || leadingSpace ) ) { nBlanks -- ; } } if ( nBlanks < 0 ) { nBlanks = 0 ; } if ( leadingSign ) { n ++ ; } else if ( leadingSpace ) { n ++ ; } n += nBlanks ; n += nLeadingZeros ; n += sx . length ( ) ; final char [ ] ca = new char [ n ] ; if ( leftJustify ) { if ( neg ) { ca [ i ++ ] = '-' ; } else if ( leadingSign ) { ca [ i ++ ] = '+' ; } else if ( leadingSpace ) { ca [ i ++ ] = ' ' ; } final char [ ] csx = sx . toCharArray ( ) ; jFirst = neg ? 1 : 0 ; for ( int j = 0 ; j < nLeadingZeros ; i ++ , j ++ ) { ca [ i ] = '0' ; } for ( int j = jFirst ; j < csx . length ; j ++ , i ++ ) { ca [ i ] = csx [ j ] ; } for ( int j = 0 ; j < nBlanks ; i ++ , j ++ ) { ca [ i ] = ' ' ; } } else { if ( ! leadingZeros ) { for ( i = 0 ; i < nBlanks ; i ++ ) { ca [ i ] = ' ' ; } if ( neg ) { ca [ i ++ ] = '-' ; } else if ( leadingSign ) { ca [ i ++ ] = '+' ; } else if ( leadingSpace ) { ca [ i ++ ] = ' ' ; } } else { if ( neg ) { ca [ i ++ ] = '-' ; } else if ( leadingSign ) { ca [ i ++ ] = '+' ; } else if ( leadingSpace ) { ca [ i ++ ] = ' ' ; } for ( int j = 0 ; j < nBlanks ; j ++ , i ++ ) { ca [ i ] = '0' ; } } for ( int j = 0 ; j < nLeadingZeros ; j ++ , i ++ ) { ca [ i ] = '0' ; } final char [ ] csx = sx . toCharArray ( ) ; jFirst = neg ? 1 : 0 ; for ( int j = jFirst ; j < csx . length ; j ++ , i ++ ) { ca [ i ] = csx [ j ] ; } } return new String ( ca ) ; }
target:  Utility method for formatting using the d conversion character.