[Fixed]-Quantize result has too many digits for current context

26👍

I was able to solve this problem by increasing the the ‘max_digits’ field option.

class Myclass(models.Model):
  my_field = models.DecimalField(max_digits=11, decimal_places=2, blank=True, null=True)

Be sure to make it large enough to fit the longest number you wish to save.

If that does not work may also need to set the precision larger by:

from decimal import getcontext
  ...
  getcontext().prec = 11

See the python decimal documentation for full context parameters.

Leave a comment