HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The floatformat
filter rounds a
floating-point number to the specified number of decimals, or one, if no decimal
argument is specified.
If the argument value is a positive number, the value will be displayed with the specified number of decimals, even if the value is an integer:
<p>{{ 7.122489|floatformat:2 }}</p>
<p>{{ 7.1|floatformat:2 }}</p>
<p>{{ 7|floatformat:2 }}</p>
If the argument value is a negative number, the value will be displayed with the specified number of decimals, only if the value has decimals:
<p>{{ 7.122489|floatformat:-2 }}</p>
<p>{{ 7.1|floatformat:-2 }}</p>
<p>{{ 7|floatformat:-2 }}</p>
You can add a g
in the argument value
to specify that the result should include a separator for each thousand:
Round a number to only two decimals, and add a thousand separator:
<h1>{{ mynumber|floatformat:"2g" }}</h1>
{{ value|floatformat:decimalsg }}
Template filters are defined by using a pipe |
character followed by the name of the filter.
Arguments are defined by using a colon :
character followed by the argument value(s).
Value | Description |
---|---|
decimals | Optional. A number specifying the number of decimals. Default value is -1, which will round the number to only one decimal, or no decimals if the number has no decimals. |
g | Optional. If present, the number will be displayed with a separator for each thousand, using local settings (using , for English and . for Norwegian. |
u | Optional. If present, the number will be displayed with a separator for each thousand, without using local settings.
If u is present g
cannot be present. |