creer to_percent(x, d)

This commit is contained in:
2017-07-26 19:11:18 +02:00
parent 52949ec15b
commit 156b5093a5
5 changed files with 25 additions and 15 deletions

View File

@@ -62,9 +62,19 @@ def to_int(x):
except ValueError:
return 0
def to_percent(x):
def to_percent(x, d):
"""Takes a float and returns a string"""
return (u"%.1f " % x).replace('.', ',') + "%"
if x == 0:
pc = ''
elif d == 2:
pc = u"%.2f " % x
elif d == 3:
pc = u"%.3f " % x
else:
pc = u"%.1f " % x
if len(pc) > 0:
pc += "%"
return pc.replace('.', ',')
@view_config(route_name='home', renderer='../templates/home.pt', permission='view')