from typing import Union


def very_long_number_formatter(num: Union[str, int, float]) -> str:
    """Apply nice string format for very big numbers like Trillions, Quadrillions, Billions etc.

    Parameters
    ----------
    num: Union[str, int, float]
        number to format
    Returns
    -------
    str:
        formatted number
    """

    if isinstance(num, str):
        try:
            num = float(num)
        except (TypeError, ValueError):
            return str(num)

    if isinstance(num, (int, float)):
        num = int(num)
        magnitude = 0
        while abs(num) >= 1000 and magnitude <= 3:
            magnitude += 1
            num /= 1000.0
        num = round(num, 1)
        return "{}{}".format(
            f"{num:f}".rstrip("0").rstrip("."),
            ["", "K", "M", "B", "T"][magnitude],
        )
    return num