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(localeData.groupingSeparator);
    result.append(s,i,i + 3);
  }
  return result;
}

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 ( localeData . groupingSeparator ) ; result . append ( s , i , i + 3 ) ; } return result ; }
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 .
