Welcome, guest | Sign In | My Account | Store | Cart
def binary_prefix(value, binary=True):
    '''Return a tuple with a scaled down version of value and it's binary prefix
    - `value`: numeric type to trim down
    - `binary`: use binary (ICE) or decimal (SI) prefix
    SI = 'kMGTPEZY'   
    unit = binary and 1024. or 1000.
    for i in range(-1, len(SI)):
        if abs(value) < unit:
        value/= unit
    return (value, i<0 and '' or (binary and SI[i].upper() + 'i' or SI[i]))