当前位置: 首页>>代码示例>>Python>>正文


Python numbers.format_decimal方法代码示例

本文整理汇总了Python中babel.numbers.format_decimal方法的典型用法代码示例。如果您正苦于以下问题:Python numbers.format_decimal方法的具体用法?Python numbers.format_decimal怎么用?Python numbers.format_decimal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在babel.numbers的用法示例。


在下文中一共展示了numbers.format_decimal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_number

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_decimal [as 别名]
def format_number(number):
    '''A locale aware formatter.'''
    return format_decimal(number, locale=g.lang_code) 
开发者ID:opendatateam,项目名称:udata,代码行数:5,代码来源:helpers.py

示例2: currencyfmt

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_decimal [as 别名]
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 
开发者ID:paxswill,项目名称:evesrp,代码行数:7,代码来源:locale.py

示例3: format_decimal

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_decimal [as 别名]
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) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:32,代码来源:i18n.py

示例4: get_formatted_value

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_decimal [as 别名]
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 
开发者ID:jobsta,项目名称:reportbro-lib,代码行数:42,代码来源:context.py

示例5: format_price

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_decimal [as 别名]
def format_price(price: Decimal) -> str:
    if price is not None and price:
        return format_decimal(price, locale='ru_RU')

    return '0' 
开发者ID:f213,项目名称:education-backend,代码行数:7,代码来源:pricing.py


注:本文中的babel.numbers.format_decimal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。