Problems formatting and performing a calculation in a budget template

Hello everyone…
I’m editing a budget template, and the main table needs to perform the following calculation:

“Assinatura Anual” field: Finds the “Quantity” field of the line items, adds them (if there’s more than one), and multiplies them by 12 (to represent per year);
“Valor por Assinatura” field: Pulls and adds the “Net Price” field of the line items;
“Investimento Anual” field: Finds the “Net Price” field of the line items, adds them (if there’s more than one), and multiplies them by 12.

I tried to configure something like the following:

"<!-- Tabela de valores -->
<div class=“container–content”>
<table class=“tabela”>
<thead>
<tr style=“background-color: #f9b915;”>
<th>Assinaturas Anual</th>
<th>Valor por Assinatura</th>
<th>Investimento Mensal</th>
<th>Investimento Anual</th>
<th>Setup</th>
</tr>
</thead>
<tbody>
{% for item in line_items %}
<tr>
<td>{{ item.quantity * 12 }}</td>

<td>
{% set valor = item.price|float %}
R$ {{ “{:,.2f}”.format(valor)|replace(“,”, “X”)|replace(“.”, “,”)|replace(“X”, “.”) }}
</td>

<td>
{% if item.hs_post_tax_amount %}
{% set mensal = item.hs_post_tax_amount|float %}
R$ {{ “{:,.2f}”.format(mensal)|replace(“,”, “X”)|replace(“.”, “,”)|replace(“X”, “.”) }}
{% else %}
R$ 0,00
{% endif %}
</td>

<td>
{% if item.hs_post_tax_amount %}
{% set anual = (item.hs_post_tax_amount|float * 12)|round(2) %}
R$ {{ “{:,.2f}”.format(anual)|replace(“,”, “X”)|replace(“.”, “,”)|replace(“X”, “.”) }}
{% else %}
R$ 0,00
{% endif %}
</td>

<td>-</td>
</tr>
{% endfor %}
</tbody>
</table>"

It worked initially, but I can’t get it to format to the Brazilian real (R$). It always ends up with a comma at the beginning, or it ignores a trailing 0 or doesn’t set the value when it goes over a thousand

My guess is that the code is generating the gross value, but I can’t find how to make this adjustment.
I really need help

Instead of doing all the replace filters, have you tried using the format_currency_value filter? It supports locales which includes the Brazilian Real

{{ valor | format_currency_value(locale="pt-BR") }}

As for your specific issue, you would need to do a bit of debugging. What is the value being pushed into your replace filters? You might need to just output every step to see what is causing the issues.

While Hubl is based off of jinja, I don’t believe it supports the .format function from jinja (in favor of their own custom filters and functions).

Just to add, here is the link to the filter documentation:
https://developers.hubspot.com/docs/reference/cms/hubl/filters#format_currency_value