money.py 文件源码

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

项目:py-money 作者: vimeo 项目源码 文件源码
def _round(amount: Decimal, currency: Currency) -> Decimal:
        sub_units = CurrencyHelper.sub_unit_for_currency(currency)
        # rstrip is necessary because quantize treats 1. differently from 1.0
        rounded_to_subunits = amount.quantize(Decimal(str(1 / sub_units).rstrip('0')),\
                                              rounding=ROUND_HALF_UP)
        decimal_precision = CurrencyHelper.decimal_precision_for_currency(currency)
        return rounded_to_subunits.quantize(\
                   Decimal(str(1 / (10 ** decimal_precision)).rstrip('0')),\
                   rounding=ROUND_HALF_UP)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号