I have a webform where I am using the Twig Computed module to calculate an amount. It is simple and straight forward: I have a field that captures the amount and I'm using Twig to multiply it to find the fee; the fee amount is a fixed rate

The Computed Value/Markup is {{ data['license_amount']|number_format(2) * 0.019 }}. It works when data['license_amount'] is lower than 999; it shows a wrong total when data['license_amount'] is higher than 999.

If the amount is 500 the value is 9.5 as it should.

If the amount is 5000 the value is returned as 0.095

  • 1
    I agree with the locale part in the comment. Thousands separator seem to play you tricks here. However, the only change I'd suggest in the case is to add the second(decimal_point) and third(thousand_sep) parameters as explained in twig.symfony.com/doc/2.x/filters/number_format.html and this should be perfectly fine.
    – itsandev
    Jun 14, 2023 at 8:33

1 Answer 1


You should drop the number_format altogether (not sure what the requirement is), or place it at the end of the calculation, i.e.

{{ (data['license_amount'] * 0.019)|number_format(2) }}

number_format is a wrapper around PHP's number_format function

From PHP's documentation page:

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

It seems like you are running the calculation on something like 5'000 or 5,000 (depending on your locale), which would explain the results you are getting.

Good luck!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.