本文整理匯總了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')