Python babel.numbers.format_number() Examples
The following are 7
code examples of babel.numbers.format_number().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
babel.numbers
, or try the search function
.
Example #1
Source File: specs.py From kerko with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: formatters.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
def localised_number(number): ''' Returns a localised unicode representation of number ''' return numbers.format_number(number, locale=i18n.get_lang())
Example #3
Source File: locale.py From evesrp with BSD 2-Clause "Simplified" License | 5 votes |
def numberfmt(number): return numbers.format_number(number, locale=get_locale())
Example #4
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def format_number(number): """See :meth:`I18n.format_number`.""" return get_i18n().format_number(number)
Example #6
Source File: specs.py From kerko with GNU General Public License v3.0 | 5 votes |
def build(self, results, criteria, active_only=False): tree = Tree() 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. if value: path = value.split(sep=self.path_separator) else: path = [value] # Build the tree path. Part of the path may or may not already # exist as the facet values are not ordered. node = tree # Start at tree root. for component in path: node = node['children'][component] # Add data at the leaf. node['node'] = { 'label': label, 'count': count, 'count_formatted': format_number(count, locale=get_locale()), 'remove_url': remove_url, 'add_url': add_url, } return self.sort_tree(tree)
Example #7
Source File: views.py From memorious with MIT License | 5 votes |
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')