public static String formatNumber(double number,int decimalPlaces){
  String s=String.valueOf(number);
  int idx1=s.indexOf('.');
  if (idx1 == -1) {
    return s;
  }
 else {
    int idx2=s.indexOf('E');
    int dp=decimalPlaces + (idx2 >= 0 ? 0 : 1);
    String t=s.substring(0,Math.min(idx1 + dp,s.length()));
    if (idx2 >= 0)     t+=s.substring(idx2);
    return t;
  }
}

public static String formatNumber ( double number , int decimalPlaces ) { String s = String . valueOf ( number ) ; int idx1 = s . indexOf ( '.' ) ; if ( idx1 == - 1 ) { return s ; } else { int idx2 = s . indexOf ( 'E' ) ; int dp = decimalPlaces + ( idx2 >= 0 ? 0 : 1 ) ; String t = s . substring ( 0 , Math . min ( idx1 + dp , s . length ( ) ) ) ; if ( idx2 >= 0 ) t += s . substring ( idx2 ) ; return t ; } }
format the given number as a string , including the given number of decimal places .
