hope simple question gets an simple answer.
I’d just like to compose Django’s filters so I get formated floating point number locale-aware:
{{123.45|floatformat:1}}
"123.5" <= correct
{{123.45|localize}}
"123,45" <= correct, in my locales decimal separator is a comma
{{123.45|floatformat:1|localize}}
"123.5" <= wrong, point instead of comma. Expected output: "123,5"
How can I apply both filters at the same time ?
Thanks.
Django’s
floatformatfilter returns a string, not actually a float number, so when you pass that value tolocalize, you are passing a string, not a number (int, float, etc) and therefore just returns the given string.To achieve what you want, you can’t combine these two filters in Django, since both return a string. To do that, you would have to make your own filter which will do the behavior you want. To make things easier, you can always start with the code in the default filters and modify that to your specification.
floatformatcode is here andlocalizeis here.