Restrict django FloatField to 2 decimal places

If you are only concerned with how your FloatField appears in forms, you can use the template filter floatformat.

From the Django Docs:

If used with a numeric integer argument, floatformat rounds a number to that many decimal places.

For example, if value = 34.23234, then in your template:

{{ value|floatformat:2 }}  # outputs 34.23

Leave a Comment