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