static String zeroPadIntString(String unpadded, int minDigits) {
        int len = unpadded.length();

        // Get the sign character (or 0 if none)
        char sign = unpadded.charAt(0);
        if ((sign != '-') && (sign != '+'))
            sign = 0;

        // The number of characters required is the number of digits,
        // plus one for the sign if present.
        int minChars = minDigits;
        if (sign != 0)
            minChars++;

        // If we already have that many characters, we're done.
        if (len >= minChars)
            return unpadded;

        // Otherwise, create the buffer
        StringBuffer buf = new StringBuffer();

        // Copy in the sign first, if present
        if (sign != 0) {
            buf.append(sign);
        }

        // Add the zeros
        int zerosNeeded = minChars - len;
        while (zerosNeeded-- != 0)
            buf.append('0');

        // Copy the rest of the unpadded string
        if (sign != 0) {
            // Skip sign
            buf.append(unpadded.substring(1, len));
        } else {
            buf.append(unpadded);
        }

        return buf.toString();
    }