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

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva