def byte(val, fmt="{:.2f}"):
    """Returns a byte representation of the input value

    :param val: value to format, must be convertible into a float
    :param fmt: optional output format string, defaults to {:.2f}

    :return: byte representation (e.g. <X> KiB, GiB, etc.) of the input value
    :rtype: string
    """

    val = float(val)
    for unit in ["", "Ki", "Mi", "Gi"]:
        if val < 1024.0:
            return "{}{}B".format(fmt, unit).format(val)
        val /= 1024.0
    return "{}GiB".format(fmt).format(val * 1024.0)