

def round_decimal(val='0', places=None, roundfactor='0', normalize=True):
    '\n    PARTIAL UNIT ROUNDING DECIMAL\n    Converts a valid float, integer, or string to a decimal number with a specified\n    number of decimal places, performs "partial unit rounding", and decimal normalization.\n\n    METHOD ARGUEMENTS:\n    `val` The value to be converted and optionally formated to decimal.\n    `places` The decimal precision is defined by integer "places" and\n        must be <= the precision defined in the decimal.Decimal context.\n    `roundfactor` (partial unit rounding factor) If purf is between -1 and 1, purf rounds up\n        (positive purf value) or down (negative purf value) in factional "purf" increments.\n    `normalize` If normalize is True (any value other than False), then rightmost zeros are truncated.\n    '
    if (str(normalize) == 'False'):
        normalize = False
    try:
        roundfactor = Decimal(str(roundfactor))
    except (InvalidOperation, ValueError):
        raise RoundedDecimalError(val=roundfactor, id=1, msg='roundfactor - InvalidOperation or ValueError')
    if (not ((abs(roundfactor) >= 0) and (abs(roundfactor) <= 1))):
        raise RoundedDecimalError(val=roundfactor, id=2, msg='roundfactor - Out of Range - must be between -1 and +1')
    try:
        if (places != None):
            places = int(places)
    except ValueError:
        raise RoundedDecimalError(val=places, id=3, msg='ValueError, Invalid Integer ')
    if (places > getcontext().prec):
        raise RoundedDecimalError(val=places, id=4, msg='places Exceeds Decimal Context Precision')
    try:
        decval = Decimal(str(val))
    except (InvalidOperation, UnicodeEncodeError):
        raise RoundedDecimalError(val=val, id=5, msg='InvalidOperation - val cannot be converted to Decimal')
    if (roundfactor and (decval % decval)):
        if (roundfactor < 0):
            roundby = 0
        else:
            roundby = ((decval / abs(decval)) * roundfactor)
        decval = (((decval // roundfactor) * roundfactor) + roundby)
    if (places != None):
        decmask = '0.'.ljust((places + 2), '0')
        decval = decval.quantize(Decimal(decmask), rounding=ROUND_DOWN)
    if normalize:
        if (decval == decval.to_integral()):
            decval = decval.quantize(Decimal('1'))
        else:
            decval.normalize()
    return decval

dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_utils/numbers.py round_decimal/VarMisuse@249/659 `roundfactor`->`decval`