Opened 7 years ago

Closed 7 years ago

#16881 closed Uncategorized (invalid)

db.backends.util.format_number fails with valid inputs

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Aymeric Augustin)

We see the error "quantize result has too many digits for current context" when using a DecimalField with max_digits=7 decimal_places=2 ie the following call fails

format_number(Decimal('914123.22'), 7, 2)

I believe this is due to the statement

context.prec = max_digits

whereas I think it should be

context.prec = max_digits + decimal_places

but I am not sure.

Change History (2)

comment:1 Changed 7 years ago by Aymeric Augustin

Description: modified (diff)

Improved formatting.

comment:2 Changed 7 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

In fact, Django interprets max_digits as the total number of digits — before and after the decimal point.


So your example should be written like this:

format_number(Decimal('914123.22'), 8, 2)
Note: See TracTickets for help on using tickets.
Back to Top