def num2eng(num, k=1024):
    """Convert input num to string with unit prefix

    Copied from durank.
    Use k=1024 for binary (e.g. kB).
    Use k=1000 for non-binary kW.

    Args:
        num: integer amount
        k: the amount that is 1k, usually 1000 or 1024.  Default is 1024

    Returns:
        numstr: string of formatted decimal number with unit prefix at end
    """
    if num > k ** 5:
        numstr = "%.1fP" % (float(num) / k ** 5)
    elif num > k ** 4:
        numstr = "%.1fT" % (float(num) / k ** 4)
    elif num > k ** 3:
        numstr = "%.1fG" % (float(num) / k ** 3)
    elif num > k ** 2:
        numstr = "%.1fM" % (float(num) / k ** 2)
    elif num > k:
        numstr = "%.1fk" % (float(num) / k)
    else:
        numstr = "%.1g" % (float(num))
    return numstr