當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。