01: /*
02: * This is free software, licensed under the Gnu Public License (GPL)
03: * get a copy from <http://www.gnu.org/licenses/gpl.html>
04: * @version $Id: Formatter.java,v 1.1 2004/03/23 11:06:40 magrokosmos Exp $
05: * @author <a href="mailto:martin.grotzke@javakaffee.de">Martin Grotzke</a>
06: */
07: package henplus.view.util;
08:
09: import java.text.NumberFormat;
10: import java.util.Locale;
11:
12: /**
13: * Knows how to format various things, like number, dates etc.<br>
14: * Created on: Mar 23, 2004<br>
15: */
16: public final class Formatter {
17:
18: private static final NumberFormat NUMBER_FORMAT = NumberFormat
19: .getNumberInstance(Locale.GERMANY);
20:
21: private Formatter() {
22: }
23:
24: /**
25: * Formats a double to a String with number-format.
26: *
27: * @param amount the <code>double</code> to be formatted
28: * @param precision an <code>int</code>. which precision should be used?
29: * @return a <code>String</code>
30: */
31: public static String formatNumber(double amount, int precision) {
32: if (amount == 0.0)
33: return null;
34: NUMBER_FORMAT.setMinimumFractionDigits(precision);
35: NUMBER_FORMAT.setMaximumFractionDigits(precision);
36: return NUMBER_FORMAT.format(amount);
37: }
38:
39: }
|