money.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:CommunityCellularManager 作者: facebookincubator 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号