def convert(value, from_unit, to_unit):
if isinstance(value, float):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (value, from_unit, to_unit)<EOL>)<EOL><DEDENT>if from_unit not in UNITS_TO_RAW:<EOL><INDENT>raise ValueError('<STR_LIT>' % from_unit)<EOL><DEDENT>if to_unit not in UNITS_TO_RAW:<EOL><INDENT>raise ValueError('<STR_LIT>' % to_unit)<EOL><DEDENT>try:<EOL><INDENT>value = Decimal(value)<EOL><DEDENT>except Exception:<EOL><INDENT>raise ValueError('<STR_LIT>' % value)<EOL><DEDENT>from_value_in_base = UNITS_TO_RAW[from_unit]<EOL>to_value_in_base = UNITS_TO_RAW[to_unit]<EOL>result = value * (from_value_in_base / to_value_in_base)<EOL>return result.normalize()<EOL>
Converts a value from `from_unit` units to `to_unit` units

:param value: value to convert
:type value: int or str or decimal.Decimal

:param from_unit: unit to convert from
:type from_unit: str

:param to_unit: unit to convert to
:type to_unit: str

>>> convert(value='1.5', from_unit='xrb', to_unit='krai')
Decimal('0.0015')