public static String convertDoubleToString(double x, int w, int d) {
	if (Double.isNaN(x)) {
		return "NaN";
	}
	java.text.DecimalFormat fmt = new java.text.DecimalFormat();
	fmt.setMaximumFractionDigits(d);
	fmt.setMinimumFractionDigits(d);
	fmt.setGroupingUsed(false);
	StringBuilder s = new StringBuilder(fmt.format(x));
	while (s.length() < w) {
		s.insert(0, ' ');
	}
	return s.toString();
}
 
public static String convertDoubleToString(double x) {
	if (Ts.mathIsInteger(x)) {
		return Ts.convertIntToString((int) x);
	}
	return convertDoubleToString(x, 5, 2);
}
 
public static String convertIntToString(int number) {
	return String.valueOf(number);
}


Back to JavaHowTo

Alumni Liaison

BSEE 2004, current Ph.D. student researching signal and image processing.

Landis Huffman