When using number_format in custom text, PHP error is triggered

Created on 6 November 2024, 3 months ago

Usage in custom text in View:

{% set total_price = total_price__number_1|render|number_format(2, '.', '')%}

Error triggered:

TypeError: number_format(): Argument #2 ($decimals) must be of type int, string given in number_format() (line 859 of /home/pumpbooks/live.pumptechnicalbooks.com/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @toddses
  • Casting the value to int seems to resolve the issue.

    Line 859: $rendered_values[] = number_format($new_value, $custom_delimiters[0] ?? 0, $custom_delimiters[1] ?? '.', $custom_delimiters[2] ?? '');

    Potential fix: $rendered_values[] = number_format($new_value, (int) $custom_delimiters[0] ?? 0, $custom_delimiters[1] ?? '.', $custom_delimiters[2] ?? '');

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Yes, that seems to be the correct fix. I'd like to clean up that piece of code a bit and write a test case - I'll open a MR soon.

Production build 0.71.5 2024