question: public static String formatDecimal ( double number , int digits ) { StringBuffer a = new StringBuffer ( ) ; for ( int i = 0 ; i < digits ; i ++ ) { if ( i == 0 ) a . append ( "." ) ; a . append ( "0" ) ; } DecimalFormat nf = new DecimalFormat ( "###,###,###,##0" + a . toString ( ) ) ; String formatted = nf . format ( number ) ; return formatted ; }
target:  format a number properly with the given number of digits