def format_number(n, max_length):
    """
    Get number in String, in a format fitting in the max_length specified
    :param n: number to transform in String
    :param max_length: maximum length authorized to display that number
    :return: a String representing this number fitting in the desired size
    """

    # First, we round the number
    s = str(int(n + 0.5))
    if len(s) > max_length or abs(n) < 1:
        # If the String of the rounded number is bigger than max_length,
        # or of the absolute value is < 1, then we return the number using an exponent
        return format(n, str(max_length - 3) + ".2G")
    else:
        # otherwise, we return the rounded number in text
        return s