My question is very simple, but I couldn't find an answer. I'm sorry if it has been answered before.
I have a DecimalField which came from a view to my template in my django application. I need to display only the integer part of it.
How can I do that?
========================= SOLUTION FOUND ========================
Sorry, I would have answered if I had permission, but only after 8 hours I can do so.
Thank you for the answers. I have found a builtin solution that worked just fine. It is a builtin template filter. The documentation follows.
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat
Basically, the usage for my purpose is something like this:
{{decimal_obj|floatformat:0}}
An even better solution is the stringformat filter:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#stringformat
Usage:
{{decimal_obj|stringformat:"d"}}
Thanks for the help. Ignacio was right ;)
If you only need to display the integral part of it then use a stringformat
of "d"
. If you need to calculate it then do it in the view.
{{ decimal_field | stringformat:'d' }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With