01: /*
02: * Created on May 5, 2004
03: *
04: */
05: package org.jmatlab.util;
06:
07: import java.text.DecimalFormat;
08:
09: /**
10: * @author Ali
11: *
12: */
13: public class FormatNumber {
14: public static final DecimalFormat decimalFormat = new DecimalFormat(
15: "0.####");
16: public static final DecimalFormat exponentFormat = new DecimalFormat(
17: "0.####E0");
18:
19: public static String format(double d) {
20: String output = null;
21: if (d == -0)
22: return "0";
23: double absd = Math.abs(d);
24: if ((absd >= 0.001 && absd <= 1000) || (d == 0)) {
25: output = decimalFormat.format(d);
26: } else {
27: output = exponentFormat.format(d);
28: }
29: return output;
30: }
31:
32: public static void main(String[] args) {
33: }
34: }
|