Twig and decimal numbers

398 views Asked by At

i have a little problem with latest version of CS-Cart. I need to insert in Document Invoice a new box with amount of Subtotal (without tax) and shipping cost.

To show this value i use this snippet:

{% set imptotale = o.display_subtotal + o.display_shipping_cost %}
{{ imptotale|number_format(2, ',', '.') }} €

Unfortunately the amount is wrong.

Example:

Subtotal: 65,10€
Shipping: 5,20€
Total: 70,30€

Value show with my snippet:

Subtotal: 65,10€
Shipping: 5,20€
Total: 70,00€

How can i show also decimal numbers?

1

There are 1 answers

0
DarkBee On

The problems lays in the fact your are sending strings towards Twig and not floats :

input (as json)

{ 
  'subtotal' : 65.10,
  'shipping' : 5.20,
  'subtotal_str' : '65,10',
  'shipping_str' : '5,20', 
}

twig

{% set total = subtotal + shipping %}

{{ subtotal | number_format(2, ',', '.')  }}
{{ shipping | number_format(2, ',', '.') }}
{{ total | number_format(2, ',', '.') }}


{% set total = subtotal_str + shipping_str %}

{{ subtotal_str }}
{{ shipping_str }}
{{ total | number_format(2, ',', '.') }}

demo