def money_str(self, with_symbol=True):
""" Format money using the currency's format string.
If amount is negative, the sign is moved to the front of the string
>>> Money(-12).money_str()
-$12.00
>>> Money(123456.789).money_str()
$123,456.79
>>> Money(987654321, currency=CURRENCIES['IDR']).money_str()
Rp 987654321
>>> Money(-987654321, currency=CURRENCIES['IDR']).money_str()
Rp -987654321
"""
# Strip the sign and move it to the front of the string
#fails if any component cannot be converted to ascii -kurtis
string = self.currency.format_str.format(
amount=abs(self.amount),
symbol=self.currency.symbol,
code=self.currency.code,
name=self.currency.name,
decimals=self.currency.decimals)
if self.amount_raw < 0:
string, n = re.subn(r'\s', r' -', string, count=1)
if n == 0:
string = '-' + string
return string
money.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录