Is there a direct approach to format numbers in jinja2?
问题 I need to format decimal numbers in jinja2. When I need to format dates, I call the strftime() method in my template, like this: {{ somedate.strftime('%Y-%m-%d') }} I wonder if there is a similar approach to do this over numbers. Thanks in advance! 回答1: You can do it simply like this, the Python way: {{ '%04d' % 42 }} {{ 'Number: %d' % variable }} Or using that method: {{ '%d' | format(42) }} I personally prefer the first one since it's exactly like in Python. 回答2: I want to highlight Joran