def size_to_str(size):
    """
    Take a size in mebibytes and return it in the biggest of the units MiB,
    GiB or TiB.

    Args:
        size (int): size to be formatted, in mebibytes

    Returns:
        str: formatted size with its unit
    """
    # user set a flag to keep memory configuration unchanged: no need to
    # compute size, just return
    if size == 0:
        return '0'

    units = ['MiB', 'GiB', 'TiB']
    max_units = len(units) - 1

    cur_size = float(size)

    prev_size = size

    index = 0
    while True:
        prev_size = cur_size
        cur_size /= 1024
        if int(cur_size) == cur_size and index < max_units:
            index += 1
            continue
        break

    return '{}{}'.format(int(prev_size), units[index])