import decimal


def transform_decimal(val, mode=None):
    """
    Transform to a decimal
        <dotted>|decimal            Decimal(val)
        <dotted>|decimal:force      Decimal(val) or raises
    """
    try:
        return decimal.Decimal(val)
    except decimal.InvalidOperation:
        if mode == 'force':
            raise
    return val