def to_integer(obj):
    """Converts `obj` to an integer.

    Args:
        obj (str|int|float): Object to convert.

    Returns:
        int: Converted integer or ``0`` if it can't be converted.

    Example:

        >>> to_integer(3.2)
        3
        >>> to_integer('3.2')
        3
        >>> to_integer('3.9')
        3
        >>> to_integer('invalid')
        0

    .. versionadded:: 4.0.0
    """
    try:
        # Convert to float first to handle converting floats as string since
        # int('1.1') would fail but this wouldn't.
        num = int(float(obj))
    except (ValueError, TypeError):
        num = 0

    return num