public static String num ( Number count ) { if ( count == null ) { return "" ; } if ( count instanceof Double || count instanceof BigDecimal ) { String s = count . toString ( ) ; if ( idx ( s , 1 ) == ' ' && s . length ( ) > 7 ) { s = slc ( s , 0 , 5 ) ; return s ; } else { return s ; } } else if ( count instanceof Integer || count instanceof Long || count instanceof Short || count instanceof BigInteger ) { String s = count . toString ( ) ; s = new StringBuilder ( s ) . reverse ( ) . toString ( ) ; CharBuf buf = CharBuf . create ( s . length ( ) ) ; int index = 0 ; for ( char c : s . toCharArray ( ) ) { index ++ ; buf . add ( c ) ; if ( index % 3 == 0 ) { buf . add ( ' ' ) ; } } if ( buf . lastChar ( ) == ' ' ) { buf . removeLastChar ( ) ; } s = buf . toString ( ) ; s = new StringBuilder ( s ) . reverse ( ) . toString ( ) ; return s ; } return count . toString ( ) ; }
Do a nice pretty print of a number . Add commas and such .