本文整理汇总了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)
示例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)
示例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
)
示例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)
示例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
示例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)
示例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
)
示例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