Skip to content
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

Decimal option crashes Quantity constructor #2068

Open
XZF0 opened this issue Oct 26, 2024 · 1 comment
Open

Decimal option crashes Quantity constructor #2068

XZF0 opened this issue Oct 26, 2024 · 1 comment

Comments

@XZF0
Copy link

XZF0 commented Oct 26, 2024

import pint
import decimal
ureg = pint.UnitRegistry(non_int_type=decimal.Decimal) 
y = ureg.Quantity('1.2345', 'm')
print(y.to('cm'))
#>>> TypeError: can't multiply sequence by non-int of type 'decimal.Decimal'

ureg = pint.UnitRegistry(non_int_type=decimal.Decimal) 
y = ureg.Quantity(1.2345, 'm')
print(y.to('cm'))
#>>> TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'
@andrewgsavage
Copy link
Collaborator

import pint
import decimal
ureg = pint.UnitRegistry(non_int_type=decimal.Decimal) 
y = ureg.Quantity(decimal.Decimal(1.2345), 'm')
print(y.to('cm'))
123.4499999999999930722083263 centimeter

Looks like the parser should convert the text number to decimal here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants