private void appendScientificNumber(StringBuffer buffer, double xx, int precision, boolean repr, boolean useSignificantNumbers) {
        int exponent = 0;
        double x = xx;

        // Run two passes to handle cases such as %.2e with the value 95.
        for (int i = 0; i < 2; i++) {
            if (x >= 1.0) {
                while (x >= 10.0) {
                    x /= 10.0;
                    exponent++;
                }
            } else {
                while (x > 0 && x < 1.0) {
                    x *= 10.0;
                    exponent--;
                }
            }
            x = MathLib.roundToPrecision(x, precision);
        }
        int absExponent = Math.abs(exponent);
        char expSign;
        if (exponent >= 0) {
            expSign = '+';
        } else {
            expSign = '-';
        }
        if (useSignificantNumbers) {
            appendSignificantNumber(buffer, x, precision, repr);
        } else {
            appendPrecisionNumber(buffer, x, precision, repr);
        }
        buffer.append('e');
        buffer.append(expSign);
        stringBufferAppend(buffer, absExponent, 10, true, 2);
    }
Only works with non-negative numbers
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java