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')

def convert(value, from_unit, to_unit):
    """
    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')
    """

    if isinstance(value, float):
        raise ValueError(
            "float values can lead to unexpected precision loss, please use a"
            " Decimal or string eg."
            " convert('%s', %r, %r)" % (value, from_unit, to_unit)
        )

    if from_unit not in UNITS_TO_RAW:
        raise ValueError('unknown unit: %r' % from_unit)

    if to_unit not in UNITS_TO_RAW:
        raise ValueError('unknown unit: %r' % to_unit)

    try:
        value = Decimal(value)
    except Exception:
        raise ValueError('not a number: %r' % value)

    from_value_in_base = UNITS_TO_RAW[from_unit]
    to_value_in_base = UNITS_TO_RAW[to_unit]

    result = value * (from_value_in_base / to_value_in_base)

    return result.normalize()