round value before formatting in order to avoid zope.i18n formatter bug
This commit is contained in:
parent
452dc0290f
commit
5ba1f5cbdd
2 changed files with 6 additions and 1 deletions
|
@ -50,9 +50,12 @@ def formatDate(dt=None, type='date', variant='medium', lang='de'):
|
|||
return fmt.format(dt or datetime.now())
|
||||
|
||||
|
||||
def formatNumber(num, type='decimal', lang='de', pattern=u'#,##0.00;-#,##0.00'):
|
||||
def formatNumber(num, type='decimal', lang='de',
|
||||
pattern=u'#,##0.00;-#,##0.00', precision=2):
|
||||
loc = locales.getLocale(lang)
|
||||
fmt = loc.numbers.getFormatter(type)
|
||||
if precision:
|
||||
num = round(num, precision) # avoid zope.i18n formatting bug
|
||||
return fmt.format(num, pattern=pattern)
|
||||
|
||||
|
||||
|
|
|
@ -15,3 +15,5 @@ Basic Formatting Functions
|
|||
|
||||
>>> format.formatNumber(17.2)
|
||||
u'17,20'
|
||||
>>> format.formatNumber(13399.99999997)
|
||||
u'13.400,00'
|
||||
|
|
Loading…
Add table
Reference in a new issue