public static String formatNumber(Object n, int length) {
        if (length == 0) {
            length = 1;
        }

        if (n instanceof Integer) {
            return String.format("%1$" + length + "d", (int) n);
        } else if (n instanceof Long) {
            return String.format("%1$" + length + "d", (long) n);
        } else {
            return String.format("%1$" + length + "s", n.toString());
        }
    }