Python babel.numbers.format_currency() Examples
The following are 9
code examples of babel.numbers.format_currency().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
babel.numbers
, or try the search function
.
Example #1
Source File: classified.py From django-classified with MIT License | 6 votes |
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)
Example #2
Source File: currency_filters.py From django-accounting with MIT License | 6 votes |
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)
Example #3
Source File: utils.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
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 )
Example #4
Source File: money.py From py-money with MIT License | 5 votes |
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)
Example #5
Source File: currencyformat.py From riko with MIT License | 5 votes |
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
Example #6
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: i18n.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def format_currency(number, currency, format=None): """See :meth:`I18n.format_currency`.""" return get_i18n().format_currency(number, currency, format)
Example #8
Source File: utils.py From ecommerce with GNU Affero General Public License v3.0 | 5 votes |
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 )
Example #9
Source File: formatters.py From PrettyPandas with MIT License | 5 votes |
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