question: private CharSequence insertGrouping ( CharSequence s ) { StringBuilder result = new StringBuilder ( s . length ( ) + s . length ( ) / 3 ) ; int digitsLength = s . length ( ) ; int i = 0 ; if ( s . charAt ( 0 ) == '-' ) { -- digitsLength ; ++ i ; result . append ( '-' ) ; } int headLength = digitsLength % 3 ; if ( headLength == 0 ) { headLength = 3 ; } result . append ( s , i , i + headLength ) ; i += headLength ; for ( ; i < s . length ( ) ; i += 3 ) { result . append ( groupingSeparator ( ) ) ; result . append ( s , i , i + 3 ) ; } return result ; }
target:  Inserts the grouping separator every 3 digits. DecimalFormat lets you configure grouping size, but you can't access that from Formatter, and the default is every 3 digits.