I am using twig to calculate numbers (or multiply). I find that the result is not calculated precisely when one of the numbers is greater than 1000. For example, the budget change number is not added correctly. Here is my twig code for the addition:
{% set current = 0 + data.current_budget|number_format(2, '.', ',') %} {% set new = 0 + data.new_budget|number_format(2, '.', ',') %} {% set change = 0 +(new - current)|number_format(2, '.', ',') %} {{ change }}
It also happens even when I wrote twig for multiplication. It seems to calculate the right result until when one of the numbers exceeds 1000. Here is my code for multiplication:
{% set net_cost = 0 %} {% for item in data.item %} {% set total_qty = (item.qty)|number_format(2,'.',',') %} {% set per_price = (item.total)|number_format(2,'.',',') %} {% set net_cost = net_cost + (total_qty * per_price ) %} {% endfor %} {{ '$ ' ~ net_cost }}
I did not realize my functions were not working as I wished until I tried with large numbers. I would love your helps! Thank you