def memory_formatter(mem):
    """
    Takes a numeric value \p mem and returns a string using the standard prefixes K,
    M, G. The printed string has one decimal digit for GB, otherwise is integral.
    """
    if mem is None: return None
    if mem < 1000:
        return str(mem)
    if mem < 1000000:
        return str(int(mem / 1000)) + ' KB'
    if mem < 1000000000:
        return str(int(mem / 1000000)) + ' MB'
    return '%0.1f GB' % (float(mem) / 1000000000.0)