public static String format(double d,int decimals){
  double factor=Math.pow(10,decimals);
  double digits=Math.round(factor * d);
  return ((int)Math.floor(digits / factor)) + "." + ((int)(digits % factor));
}

public static String format ( double d , int decimals ) { double factor = Math . pow ( 10 , decimals ) ; double digits = Math . round ( factor * d ) ; return ( ( int ) Math . floor ( digits / factor ) ) + "." + ( ( int ) ( digits % factor ) ) ; }
returns d as a string truncated to the specified number of decimal places
