I have a value that I’m passing to a template which is 113.999.
When I do {{ value|floatformat:"-1" }} it outputs 114.0.
View code:
some_var = 113.999
Template code:
{{ some_var|floatformat }}
My understanding of floatformat was that it should round, and then not display the decimal part if it was all zeroes.
Is floatformat wrong, or am I?
Interesting, by exploring the code, I’ve found that the quantizing happens after the checking of integer. Thus
113.999is quantized after it is checked against integer and failed.IMO, well I’m not an expert of number notation :),
114.0here represents a rounded-up value and it’s not an originally114.If you really don’t want this behavior, a quick and awkward way is
{{ value|floatformat|floatformat }}…Furthermore,
floatformatuses-1by default, thus{{ value|floatformat }}is enough in your code.