private void appendPrecisionNumber(StringBuffer buffer, double pNumber, int precision, boolean requirePeriod) {
        double number = MathLib.roundToPrecision(pNumber, precision);
        double iPart = Math.floor(number);
        double fPart = number - iPart;

        for (int i = 0; i < precision; i++) {
            fPart *= 10.0;
        }
        fPart = MathLib.round(iPart + fPart) - iPart;

        stringBufferAppend(buffer, iPart, 10, true, 0);

        if (requirePeriod || precision > 0) {
            buffer.append('.');
        }

        stringBufferAppend(buffer, fPart, 10, false, precision);
    }
Only works with non-negative numbers
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java