Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Last active August 29, 2015 14:10
Show Gist options
  • Save balazs-endresz/fda4f55c6f47e57b40f7 to your computer and use it in GitHub Desktop.
Save balazs-endresz/fda4f55c6f47e57b40f7 to your computer and use it in GitHub Desktop.
Do both rounding and float formatting in django templates
{{ value|floatformat|floatformat }}
or:
{{ value|floatformat:-1|floatformat:-1 }}
1.0 -> 1
1.01 -> 1 # this would be 1.0 with one floatformat filter
1.10 -> 1.1
1.123 -> 1.1
1.9 -> 1.9
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#floatformat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment