views:

279

answers:

3

I would like something similar to the string formatting from the standard library.

'%' Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.

A: 

Maybe you can use stringformat template filter.

aeby
Thanks, but I have tried `|stringformat:"%"` and it did not work
jbochi
The `stringformat` filter does string interpolation, not string formatting.
Ignacio Vazquez-Abrams
+2  A: 

The newness of string.Formatter() means that Django is not likely to support it built-in. Either write or find a template tag or filter that implements it.

Ignacio Vazquez-Abrams
+1  A: 

In case somebody is looking for the answser, this is how I solved the problem with a custom templatetag:

from django import template

register = template.Library()

@register.filter
def percentage(decimal):
    return format(decimal, "%")
jbochi