def trim(x, mantissa_display_length=12):
    """Return trimmed form of real x (a string).

    Gives only 12 significant digits after initial
    sequence of 9s ends.
    Note that x is truncated, not rounded.

    Args:
        x (str): A string representation of real in (0,1).
            It is assumed that x starts with '0.'.
        mantissa_display_length (int): Precision desired.
            The output is trimmed to show at most this many
            significant digits after the initial segment of 9s.
            Defaults to 12.

    Returns:
        str: the trimmed string.

    Example:
        >>> trim('0.9991234567890', 4)
        '0.9991234'
    """

    x0 = x+'0'
    first_non_9_position = \
        min([i for i in range(2, len(x0)) if x0[i] < '9'])
    return x[:first_non_9_position + mantissa_display_length]