Django FloatField in ModelForm with 2 precision points

I have a FloatField in one of my models. I add / edit it using ModelForms. What I need is that when editing, the Float value stored in the FloatField should display exactly with 2 precision points.

those. if my stored value is equal 1000.0 or 1000.123, I want the initial value to be displayed in the form input field 1000.00 or 1000.12.

Any suggestion on an approach would be appreciated. Thank you all.

+8
source share
1 answer

I do not know your use case, but use will solve your problem DecimalField

: , 999 2 , :

models.DecimalField(..., max_digits=5, decimal_places=2)
+11

All Articles