0

I am trying to round a decimal number this is my number and my code

68.125 
the output should be 68.13 and I get 68.12

code:

{% set v_cuotas = doc.saldo_contrato/doc.plazo %}
VALUE: <span class="texto_liviano"></span>{{v_cuotas|round(2)|float}}<br>

Thanks in advance

Israel
  • 121
  • 10
  • Probably this question will help you: https://stackoverflow.com/questions/11260155/how-to-use-float-filter-to-show-just-two-digits-after-decimal-point – dimasdmm Feb 12 '20 at 22:44
  • Yes I am, removing float the value is the same 68.12 and I want 68.13 – Israel Feb 12 '20 at 22:45

1 Answers1

0

A minimal example, that produces the desired rounding looks like this:

>>> from decimal import Decimal, ROUND_HALF_UP
>>> Decimal(Decimal('68.125').quantize(Decimal('0.01'), rounding=ROUND_HALF_UP))                               
Decimal('68.13')

You can also write a custom Jinja filter if you want use it the same way like the built in round filter.

Dauros
  • 9,294
  • 2
  • 20
  • 28