本文整理汇总了Python中moneyed.localization.format_money函数的典型用法代码示例。如果您正苦于以下问题:Python format_money函数的具体用法?Python format_money怎么用?Python format_money使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_money函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __unicode__
def __unicode__(self):
kwargs = {'money': self, 'decimal_places': DECIMAL_PLACES}
if self.is_localized:
locale = get_current_locale()
if locale:
kwargs['locale'] = locale
return format_money(**kwargs)
示例2: format_money_remove_aud
def format_money_remove_aud(self, **kwargs):
"""
Monkey patch money.Money.format so that the default currency (AUD) isn't displayed
when calling Money.format()
@author: Alex Hayes <[email protected]>
"""
return format_money(self, **kwargs).replace('A$', '$')
示例3: moneyformat
def moneyformat(value, currency = 'PLN', decimal_pos = 2, locale = None):
locale = get_money_locale(locale)
if isinstance(value, Money):
pass
else:
value = Money(value, currency = get_currency(str(currency)))
return format_money(value, decimal_places = decimal_pos, locale = locale)
示例4: format_money
def format_money(self, money):
"""Returns locale formated money
:param money: Money
:type money: moneyed.Money
:rtype: unicode
"""
return format_money(money, locale=self.locale())
示例5: test_format_money
def test_format_money(self):
# Two decimal places by default
assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
# No decimal point without fractional part
assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
# Locale format not included, should fallback to DEFAULT
assert format_money(self.one_million_bucks, locale='es_ES') == 'US$1,000,000.00'
# locale == pl_PL
one_million_pln = Money('1000000', 'PLN')
# Two decimal places by default
assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
assert format_money(self.one_million_bucks, locale='pl_PL') == 'US$1 000 000,00'
# No decimal point without fractional part
assert format_money(one_million_pln, locale='pl_PL',
decimal_places=0) == '1 000 000 zł'
示例6: __str__
def __str__(self):
from moneyed.localization import format_money
return format_money(self)
示例7: currency
def currency(value):
return format_money(value, locale=DJANGO)
示例8: test_format_money
def test_format_money(self):
# Two decimal places by default
assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
# No decimal point without fractional part
assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
示例9: test_format_money
def test_format_money(self):
# Two decimal places by default
assert format_money(self.one_million_bucks) == 'US$1,000,000.00'
# No decimal point without fractional part
assert format_money(self.one_million_bucks, decimal_places=0) == 'US$1,000,000'
# locale == pl_PL
one_million_pln = Money('1000000', 'PLN')
# Two decimal places by default
assert format_money(one_million_pln, locale='pl_PL') == '1 000 000,00 zł'
# overriden sign/format locale display default sign with locale group parameter
assert format_money(self.one_million_bucks, locale='pl_PL') == 'US$1 000 000,00'
# non overriden sign/format locale display default money sign with default group parameter
assert format_money(self.one_million_bucks, locale='fr_FR') == 'US$1,000,000.00'
# No decimal point without fractional part
assert format_money(one_million_pln, locale='pl_PL', decimal_places=0) == '1 000 000 zł'
# add different sign for money USD in locale pl_PL
_sign('pl_PL', moneyed.USD, prefix='$')
assert format_money(self.one_million_bucks, locale='pl_PL') == '$1 000 000,00'
# default locale display correct money sign with default group parameter
assert format_money(self.one_million_euros) == '1,000,000.00 €'
# non overriden sign/format locale display default money sign with default group parameter
assert format_money(self.one_million_euros, locale='fr_FR') == '1,000,000.00 €'
# overriden sign/locale locale display default money sign with locale group parameter
assert format_money(self.one_million_euros, locale='en_US') == '1,000,000.00 €'
# add format for fr_FR locale
_format("fr_FR", group_size=3, group_separator=" ", decimal_point=",",
positive_sign="", trailing_positive_sign="",
negative_sign="-", trailing_negative_sign="",
rounding_method=ROUND_HALF_EVEN)
# overriden format locale display correct sign with locale group parameter
assert format_money(self.one_million_euros, locale='fr_FR') == '1 000 000,00 €'