private static void stringBufferAppend(StringBuffer sb, double pValue, int base, boolean printZero, int mminDigits) {
        double value = pValue;
        int startPos = sb.length();
        int minDigits = mminDigits;
        while (value > 0 || minDigits > 0) {
            double newValue = Math.floor(value / base);
            sb.append(digits[(int) (value - (newValue * base))]);
            value = newValue;
            minDigits--;
        }
        int endPos = sb.length() - 1;
        if (startPos > endPos && printZero) {
            sb.append('0');
        } else {
            // Note that the digits are in reverse order now, so we need to correct it.
            // We can't use StringBuffer.reverse because that reverses the entire string

            int swapCount = (1 + endPos - startPos) / 2;
            for (int i = swapCount - 1; i >= 0; i--) {
                int leftPos = startPos + i;
                int rightPos = endPos - i;
                char left = sb.charAt(leftPos);
                char right = sb.charAt(rightPos);
                sb.setCharAt(leftPos, right);
                sb.setCharAt(rightPos, left);
            }
        }
    }
Precondition: value >= 0
Precondition: 2 <= base <= 16
@param sb the stringbuffer to append to
@param pValue the value to append
@param base the base to use when formatting (typically 8, 10 or 16)
@param mminDigits min digits
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/StringLib.java