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).

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

toddses created an issue. See original summary.

toddses’s picture

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] ?? '');

tr’s picture

Version: 2.1.0 » 2.1.x-dev
Priority: Major » Normal

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.