def get_float_40bit(sequence, return_string=False):
    """Return a number represented by the first 5 bytes of 'sequence'.

    If 'sequence' is not bytes-like, its first 5 values must
    be numbers in range 0-255. These five bytes represent the number
    as a 40-bit float.

    By default, return a float. If 'return_string' is True, return
    a string formatted {:.0f} for whole numbers, {:f} otherwise.
    """
    if sequence[0]:
        exponent = sequence[0] - 0x80

        mantissa_bytes = bytes((sequence[1] & 0x7f,)) + bytes(sequence[2:5])
        mantissa = int.from_bytes(mantissa_bytes, 'big') / 2**32

        result = 2**exponent * (0.5 + mantissa)

    else:
        result = 0.0

    if return_string:
        return f'{result:.0f}' if result.is_integer() else f'{result:f}'

    else:
        return result