本文整理汇总了Python中babel.numbers.format_number方法的典型用法代码示例。如果您正苦于以下问题:Python numbers.format_number方法的具体用法?Python numbers.format_number怎么用?Python numbers.format_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.numbers
的用法示例。
在下文中一共展示了numbers.format_number方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_number [as 别名]
def build(self, results, criteria, active_only=False):
items = []
for value, count in results:
if value or self.missing_label:
value, label = self.decode(value, default_value=value, default_label=value)
remove_url = criteria.build_remove_filter_url(self, value)
if remove_url or active_only:
add_url = None
else:
add_url = criteria.build_add_filter_url(self, value)
if remove_url or add_url: # Only items with an URL get displayed.
items.append({
'label': label,
'count': count,
'count_formatted': format_number(count, locale=get_locale()),
'remove_url': remove_url,
'add_url': add_url,
})
return self.sort_items(items)
示例2: localised_number
# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_number [as 别名]
def localised_number(number):
''' Returns a localised unicode representation of number '''
return numbers.format_number(number, locale=i18n.get_lang())
示例3: numberfmt
# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_number [as 别名]
def numberfmt(number):
return numbers.format_number(number, locale=get_locale())
示例4: format_number
# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_number [as 别名]
def format_number(self, number):
"""Returns the given number formatted for the current locale. Example::
>>> format_number(1099, locale='en_US')
u'1,099'
:param number:
The number to format.
:returns:
The formatted number.
"""
return numbers.format_number(number, locale=self.locale)
示例5: number_filter
# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_number [as 别名]
def number_filter(s, default=''):
if s is None or s == 0 or not len(str(s)):
return default
return format_number(s, locale='en_GB')