Reputation: 210
I would like to round up a decimal value as a result of a division in Jinja template is there a way I can do this?
I have tried doing it like this:
<td>{{'%0.2f'|format(spend[0] / user[0] |float ) }}</td>
but I got an error:
TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float'
if the result of the division is for example:
666.6666666666666666666666667
it should be rounded to 666.67
Is there a way I can achieve this?
Upvotes: 1
Views: 2021
Reputation: 39194
You do have two issues:
round
filter for that purposeGiven those two remarks, your snippet of code should be:
<td>
{{ ((spend[0] | float) / (user[0] | float)) | round(2) }}
</td>
Upvotes: 2