We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currently only float (or compatible types including int) work with format_compact_decimal.
float
int
format_compact_decimal
Using decimal.Decimal in format_compact_decimal results in unsupported operand type(s) for /: 'decimal.Decimal' and 'float'
decimal.Decimal
unsupported operand type(s) for /: 'decimal.Decimal' and 'float'
Using str results in bad operand type for abs(): 'str'
str
bad operand type for abs(): 'str'
>>> from babel.numbers import * >>> import decimal >>> format_compact_decimal(decimal.Decimal("1000")) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "babel/numbers.py", line 450, in format_compact_decimal number, format = _get_compact_format(number, format_type, locale, fraction_digits) File "babel/numbers.py", line 472, in _get_compact_format number = number / (magnitude / (10 ** (pattern.count("0") - 1))) TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float' >>> format_compact_decimal("1000") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "babel/numbers.py", line 450, in format_compact_decimal number, format = _get_compact_format(number, format_type, locale, fraction_digits) File "babel/numbers.py", line 463, in _get_compact_format if abs(number) >= magnitude: TypeError: bad operand type for abs(): 'str'
Just like format_decimal, it should probably return the correctly formatted number.
Possibly we can cast it to a float or even int in the function to get the compact format
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Overview Description
Currently only
float
(or compatible types includingint
) work withformat_compact_decimal
.Using
decimal.Decimal
informat_compact_decimal
results inunsupported operand type(s) for /: 'decimal.Decimal' and 'float'
Using
str
results inbad operand type for abs(): 'str'
Steps to Reproduce
Expected Results
Just like format_decimal, it should probably return the correctly formatted number.
Additional Information
Possibly we can cast it to a float or even int in the function to get the compact format
The text was updated successfully, but these errors were encountered: