我正在尝试舍入一个十进制数字这是我的数字和代码
68.125
the output should be 68.13 and I get 68.12代码:
{% set v_cuotas = doc.saldo_contrato/doc.plazo %}
VALUE: <span class="texto_liviano"></span>{{v_cuotas|round(2)|float}}<br>提前感谢
发布于 2020-02-21 17:25:54
生成所需舍入的最小示例如下所示:
>>> from decimal import Decimal, ROUND_HALF_UP
>>> Decimal(Decimal('68.125').quantize(Decimal('0.01'), rounding=ROUND_HALF_UP))
Decimal('68.13')如果你想像使用内置的round过滤器一样使用它,你也可以编写一个custom Jinja filter。
https://stackoverflow.com/questions/60197906
复制相似问题