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


Python numbers.format_currency方法代码示例

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


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

示例1: currency

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def currency(value, currency=None):
    """
    Format decimal value as currency
    """
    try:
        value = D(value)
    except (TypeError, InvalidOperation):
        return ""

    # Using Babel's currency formatting
    # http://babel.pocoo.org/en/latest/api/numbers.html#babel.numbers.format_currency

    kwargs = {
        'currency': currency or CURRENCY,
        'locale': to_locale(get_language() or settings.LANGUAGE_CODE)
    }

    return format_currency(value, **kwargs) 
开发者ID:slyapustin,项目名称:django-classified,代码行数:20,代码来源:classified.py

示例2: currency_formatter

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def currency_formatter(value, currency=None):
    """
    Format decimal value as currency
    """
    try:
        value = D(value)
    except (TypeError, InvalidOperation):
        return ""
    # Using Babel's currency formatting
    # http://babel.pocoo.org/docs/api/numbers/#babel.numbers.format_currency
    currency = currency or settings.ACCOUNTING_DEFAULT_CURRENCY
    kwargs = {
        'currency': currency,
        'format': getattr(settings, 'CURRENCY_FORMAT', None),
        'locale': to_locale(get_language()),
    }
    return format_currency(value, **kwargs) 
开发者ID:dulacp,项目名称:django-accounting,代码行数:19,代码来源:currency_filters.py

示例3: fmt_currency

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def fmt_currency(amt):
    """
    Using :py:attr:`~biweeklybudget.settings.LOCALE_NAME` and
    :py:attr:`~biweeklybudget.settings.CURRENCY_CODE`, return ``amt`` formatted
    as currency.

    :param amt: The amount to format; any numeric type.
    :return: ``amt`` formatted for the appropriate locale and currency
    :rtype: str
    """
    return format_currency(
        amt, settings.CURRENCY_CODE, locale=settings.LOCALE_NAME
    ) 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:15,代码来源:utils.py

示例4: format

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def format(self, locale: str='en_US') -> str:
        """Returns a string of the currency formatted for the specified locale"""

        return format_currency(self.amount, self.currency.name, locale=locale) 
开发者ID:vimeo,项目名称:py-money,代码行数:6,代码来源:money.py

示例5: parser

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def parser(amount, objconf, skip=False, **kwargs):
    """ Parsers the pipe content

    Args:
        amount (Decimal): The amount to format
        objconf (obj): The pipe configuration (an Objectify instance)
        skip (bool): Don't parse the content

    Returns:
        dict: The formatted item

    Examples:
        >>> from decimal import Decimal
        >>> from meza.fntools import Objectify
        >>>
        >>> objconf = Objectify({'currency': 'USD'})
        >>> parser(Decimal('10.33'), objconf) == '$10.33'
        True
    """
    if skip:
        parsed = kwargs['stream']
    elif amount is not None:
        try:
            parsed = format_currency(amount, objconf.currency)
        except ValueError:
            parsed = NaN
    else:
        parsed = NaN

    return parsed 
开发者ID:nerevu,项目名称:riko,代码行数:32,代码来源:currencyformat.py

示例6: format_currency

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def format_currency(self, number, currency, format=None):
        """Returns a formatted currency value. Example::

            >>> format_currency(1099.98, 'USD', locale='en_US')
            u'$1,099.98'
            >>> format_currency(1099.98, 'USD', locale='es_CO')
            u'US$\\xa01.099,98'
            >>> format_currency(1099.98, 'EUR', locale='de_DE')
            u'1.099,98\\xa0\\u20ac'

        The pattern can also be specified explicitly::

            >>> format_currency(1099.98, 'EUR', u'\\xa4\\xa4 #,##0.00',
            ...                 locale='en_US')
            u'EUR 1,099.98'

        :param number:
            The number to format.
        :param currency:
            The currency code.
        :param format:
            Notation format.
        :returns:
            The formatted currency value.
        """
        return numbers.format_currency(number, currency, format=format,
                                       locale=self.locale) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:29,代码来源:i18n.py

示例7: format_currency

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def format_currency(currency, amount, format=None, locale=None):  # pylint: disable=redefined-builtin
    locale = locale or to_locale(get_language())
    format = format or getattr(settings, 'OSCAR_CURRENCY_FORMAT', None)

    return default_format_currency(
        amount,
        currency,
        format=format,
        locale=locale
    ) 
开发者ID:edx,项目名称:ecommerce,代码行数:12,代码来源:utils.py

示例8: as_currency

# 需要导入模块: from babel import numbers [as 别名]
# 或者: from babel.numbers import format_currency [as 别名]
def as_currency(currency='USD', locale=LOCALE_OBJ):
    @_surpress_formatting_errors
    def inner(v):
        return numbers.format_currency(v, currency=currency, locale=LOCALE_OBJ)
    return inner 
开发者ID:HHammond,项目名称:PrettyPandas,代码行数:7,代码来源:formatters.py


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