[Fixed]-Django – remove trailing zeroes for a Decimal in a template

31👍

The solution is to use the normalize() method:

{{ balance.bitcoins.normalize }}

6👍

Try {{ balance.bitcoins|floatformat:"-3" }}.

https://docs.djangoproject.com/en/stable/ref/templates/builtins/#floatformat:

If the argument passed to floatformat is negative, it will round a
number to that many decimal places – but only if there’s a decimal
part to be displayed.

👤Aivar

Leave a comment