-
Notifications
You must be signed in to change notification settings - Fork 2.4k
"Convert To Number" should use decimal.Decimal #5409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree in general, but we cannot change the return value type from
|
I ended up using Decimals out of necessity:
I am aware, it's slower and more code than float, yet, especially in testing/measuring, rather slow and right. |
I'm aware of benefits of using Decimal, but it doesn't change the fact that we cannot change the default return value. Do you have opinions about the alternatives I proposed? |
This I found most plausible, some "type=Decimal" keyword argument . Convert To Decimal and other would pollute keywords. |
Ok, let's implement return TypeInfo.from_type_hint(type).convert(value) The above implementation would happily convert to any type, though, and we probably wanted this to always return a number. Instead of checking the result = TypeInfo.from_type_hint(type).convert(value)
if not isinstance(result, Number): # `from numbers import Number` needed for this to work
raise TypeError(...)
return result Using the existing type conversion logic would be simple and would also automatically support all numeric types the conversion logic supports. At the moment it means Regarding to changing the default from Are your @ilfirin-ms interested to implement this enhancement? If yes, I can add this to RF 7.4 scope. |
"Convert To Number" should use decimal, instead of documenting float precision problem.
could be substituted by (not thoroughly tested, can do, if there is demand)
The text was updated successfully, but these errors were encountered: