private String expFormat(double d) {
        String f = "";
        int e = 0;
        double dd = d;
        double factor = 1;
        while (dd > 10) {
            e++;
            factor /= 10;
            dd = dd / 10;
        }

        while (dd < 1) {
            e--;
            factor *= 10;
            dd = dd * 10;
        }

        if (((fmt == 'g') || (fmt == 'G')) && (e >= -4) && (e < precision)) {
            return fixedFormat(d);
        }

        d = d * factor;
        f = f + fixedFormat(d);

        if ((fmt == 'e') || (fmt == 'g')) {
            f = f + "e";
        } else {
            f = f + "E";
        }

        String p = "000";
        if (e >= 0) {
            f = f + "+";
            p = p + e;
        } else {
            f = f + "-";
            p = p + (-e);
        }

        return f + p.substring(p.length() - 3, p.length());
    }