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 €'
from django import template import moneyed from moneyed.localization import _format, format_money, _sign register = template.Library() # The default currency formatting of py-moneyed/djmoney doesn't do # what we want, so we set up a custom one here, applying a consistent # format that always prefixes the three-letter currency code and # symbol. DJANGO = "django" _format(DJANGO, group_size=3, group_separator=",", decimal_point=".", positive_sign="", trailing_positive_sign="", negative_sign="-", trailing_negative_sign="", rounding_method=ROUND_HALF_EVEN) # The DSF mostly only deals in USD with occasional grants iN EUR, but # we set up a few other currencies here just to be safe. # # Any currencies not defined here will fall back to the py-moneyed # default formatter. _sign(DJANGO, moneyed.AUD, prefix='AUD $') _sign(DJANGO, moneyed.CAD, prefix='CAD $') _sign(DJANGO, moneyed.EUR, prefix='EUR €') _sign(DJANGO, moneyed.GBP, prefix='GBP £') _sign(DJANGO, moneyed.JPY, prefix='JPY ¥') _sign(DJANGO, moneyed.NZD, prefix='NZD $') _sign(DJANGO, moneyed.USD, prefix='USD $')
from decimal import ROUND_HALF_EVEN import moneyed from moneyed.localization import _sign, _format _sign("en_GB", moneyed.GBP, prefix="£") _format( "en_GB", group_size=3, group_separator=",", decimal_point=".", positive_sign="", trailing_positive_sign="", negative_sign="-", trailing_negative_sign="", rounding_method=ROUND_HALF_EVEN, )
from decimal import ROUND_HALF_EVEN import moneyed from moneyed.localization import _sign, _format _sign('en_GB', moneyed.GBP, prefix='£') _format('en_GB', group_size=3, group_separator=',', decimal_point='.', positive_sign='', trailing_positive_sign='', negative_sign='-', trailing_negative_sign='', rounding_method=ROUND_HALF_EVEN)