Python babel.numbers.format_decimal() Examples
The following are 6
code examples of babel.numbers.format_decimal().
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: helpers.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def format_number(number): '''A locale aware formatter.''' return format_decimal(number, locale=g.lang_code)
Example #2
Source File: locale.py From evesrp with BSD 2-Clause "Simplified" License | 5 votes |
def currencyfmt(currency): # We're only formatting ISK, so it has a bit of a special format number = numbers.format_decimal(currency, format="#,##0.00;-#", locale=get_locale()) return number
Example #3
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def format_decimal(self, number, format=None): """Returns the given decimal number formatted for the current locale. Example:: >>> format_decimal(1.2345, locale='en_US') u'1.234' >>> format_decimal(1.2346, locale='en_US') u'1.235' >>> format_decimal(-1.2346, locale='en_US') u'-1.235' >>> format_decimal(1.2345, locale='sv_SE') u'1,234' >>> format_decimal(12345, locale='de') u'12.345' The appropriate thousands grouping and the decimal separator are used for each locale:: >>> format_decimal(12345.5, locale='en_US') u'12,345.5' :param number: The number to format. :param format: Notation format. :returns: The formatted decimal number. """ return numbers.format_decimal(number, format=format, locale=self.locale)
Example #4
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def format_decimal(number, format=None): """See :meth:`I18n.format_decimal`.""" return get_i18n().format_decimal(number, format)
Example #5
Source File: context.py From reportbro-lib with GNU Affero General Public License v3.0 | 5 votes |
def get_formatted_value(self, value, parameter, object_id, pattern=None, is_array_item=False): rv = '' if is_array_item and parameter.type == ParameterType.simple_array: value_type = parameter.array_item_type else: value_type = parameter.type if value_type == ParameterType.string: rv = value elif value_type in (ParameterType.number, ParameterType.average, ParameterType.sum): if pattern: used_pattern = pattern pattern_has_currency = (pattern.find('$') != -1) else: used_pattern = parameter.pattern pattern_has_currency = parameter.pattern_has_currency if used_pattern: try: value = format_decimal(value, used_pattern, locale=self.pattern_locale) if pattern_has_currency: value = value.replace('$', self.pattern_currency_symbol) rv = value except ValueError: error_object_id = object_id if pattern else parameter.id raise ReportBroError( Error('errorMsgInvalidPattern', object_id=error_object_id, field='pattern', context=value)) else: rv = str(value) elif value_type == ParameterType.date: used_pattern = pattern if pattern else parameter.pattern if used_pattern: try: rv = format_datetime(value, used_pattern, locale=self.pattern_locale) except ValueError: error_object_id = object_id if pattern else parameter.id raise ReportBroError( Error('errorMsgInvalidPattern', object_id=error_object_id, field='pattern', context=value)) else: rv = str(value) return rv
Example #6
Source File: pricing.py From education-backend with MIT License | 5 votes |
def format_price(price: Decimal) -> str: if price is not None and price: return format_decimal(price, locale='ru_RU') return '0'