You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formatting a negative number with the rounding mode decimal.ROUND_CEILING yields a wrong result.
Steps to Reproduce
frombabel.numbersimportdecimal, format_decimalwithdecimal.localcontext(decimal.Context(rounding=decimal.ROUND_CEILING)):
x=-100.75x_formatted=format_decimal(x, format="#")
# For comparison: Round with the decimal class directlyx_decimal=decimal.Decimal(x)
x_decimal_rounded=round(x_decimal, 0)
print(x_formatted, x_decimal_rounded)
# -101 -100
Actual Results
"-101"
Expected Results
"-100"
Additional Information
The issue, as far as I could understand the problem in the Babel code, is that only a flag is set for a negative number in order to add it again at the end of processing.
With this rounding rule, however, this must be taken into account. Currently in NumberPattern._quantize_value()-100.75 is rounded in the same way as 100.75, which gives 101 as the result. However, for -100.75 this corresponds to the rounding rule decimal.ROUND_UP, not decimal.ROUND_CEILING.
The text was updated successfully, but these errors were encountered:
Overview Description
Formatting a negative number with the rounding mode decimal.ROUND_CEILING yields a wrong result.
Steps to Reproduce
Actual Results
"-101"
Expected Results
"-100"
Additional Information
The issue, as far as I could understand the problem in the Babel code, is that only a flag is set for a negative number in order to add it again at the end of processing.
With this rounding rule, however, this must be taken into account. Currently in
NumberPattern._quantize_value()
-100.75
is rounded in the same way as100.75
, which gives101
as the result. However, for-100.75
this corresponds to the rounding rule decimal.ROUND_UP, not decimal.ROUND_CEILING.The text was updated successfully, but these errors were encountered: