adodero
adodero

Reputation: 71

Django DecimalField not accepting 0 if decimal_places == max_digits

I define a DecimalField on a model with the decimal_places attribute equal to the max_digits attribute (to store a value < 1), like so:

class MyModel(Model):
    my_field = DecimalField(max_digits=5, decimal_places=5)

In a form (the django admin site for instance), this field won't take 0, I get the following error:

Ensure that there are no more than 0 digits before the decimal point.

But it will take 0.0 :/

Anyone with the same issue? I can't find posts about it. Is this a bug or is there a reason for this behaviour?

Upvotes: 3

Views: 2866

Answers (1)

user2059525
user2059525

Reputation: 19

max_digit = number of digits after decimal point + number of digits before decimal point. so if max_digit == decimal_digit, then number of digits before decimal can be atmost 0.

Upvotes: 2

Related Questions