[Fixed]-Django DecimalField generating "quantize result has too many digits for current context" error on save

34👍

The problem is that all the right-of-the-decimal decimal_places are consumed by every instance, regardless of whether you have non-zero digits there, leaving only (max_digits - decimal_places) digits for left-of-the-decimal.

So for DecimalField(max_digits=2,decimal_places=2), there’s room for zero digits to the left of the decimal, and “1.5” won’t fit. And for DecimalField(max_digits=11,decimal_places=8), there’s room for only three digits to the left of the decimal, and “1005.7” won’t fit.

Expand your max_digits and the values will work.

👤gojomo

Leave a comment