I'm trying to display numbers in my Django templates with
e.g. 76384.8739439 -> 76,384.87
Django has template tags to achieve both these.
I can't seem to find a way to do both at the same time without writing my own custom template filter. Anybody know of an easier solution?
You use the format specification language expression '{:,}' to convert the integer number 1000000 to a string with commas as thousand separators.
Per Format Specification Mini-Language, The ',' option signals the use of a comma for a thousands separator. For a locale aware separator, use the 'n' integer presentation type instead.
Method 1: using f-stringThe inner part within the curly brackets : , says to format the number and use commas as thousand separators. Example 1: Format the number and add commas as a thousand separators to use the ',d' formatting syntax in the format() function.
{{ value|floatformat:2|intcomma }}
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