Revision as of 04:21, 23 November 2010 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett