def sizeof_fmt(size, suffix='B'):
    try:
        size = int(size)
    except ValueError:
        return None
    if size <= 0:
        return '0 %s' % suffix

    size_name = ('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
    i = int(math.floor(math.log(size,1024)))
    if i >= len(size_name):
        i = len(size_name)-1
    p = math.pow(1024,i)
    s = size/p
    # round to 3 significant digits
    s = round(s, 2-int(math.floor(math.log10(s))))
    if s.is_integer():
        s = int(s)
    if s > 0:
        return '%s %s%s' % (s, size_name[i], suffix)
    else:
        return '0 %s' % suffix
Return decoded field value from the record string.
dataset/ETHPy150Open NVIDIA/DIGITS/digits/utils/__init__.py/sizeof_fmt--crossover with--dataset/ETHPy150Open kennethreitz/tablib/tablib/packages/dbfpy3/fields.py/DbfFieldDef.decodeFromRecord