def format_number(number, SI=True, space=' '):
    """Return a human-readable metric-like string representation
    of a number.

    :param number: the number to be converted to a human-readable form
    :param SI: If is False, this function will use the convention
        that 1 kilobyte = 1024 bytes, otherwise, the convention
        that 1 kilobyte = 1000 bytes will be used
    :param space: string that will be placed between the number
        and the SI prefix
    :return: a human-readable metric-like string representation of
        *number*
    """
    symbols = [ ' ', # (none)
                'k', # kilo
                'M', # mega
                'G', # giga
                'T', # tera
                'P', # peta
                'E', # exa
                'Z', # zetta
                'Y'] # yotta

    if SI: step = 1000.0
    else: step = 1024.0

    thresh = 999
    depth = 0
    max_depth = len(symbols) - 1

    # we want numbers between 0 and thresh, but don't exceed the length
    # of our list.  In that event, the formatting will be screwed up,
    # but it'll still show the right number.
    while number > thresh and depth < max_depth:
        depth  = depth + 1
        number = number / step

    if type(number) == type(1) or (int(number) == number):
        number = int(number)
        format = '%3i%s%s'
    elif number < 9.95:
        # must use 9.95 for proper sizing.  For example, 9.99 will be
        # rounded to 10.0 with the .1f format string (which is too long)
        format = '%3.1f%s%s'
    else:
        format = '%3.0f%s%s'

    return(format % (float(number or 0), space, symbols[depth]))