Doesn't play nice with number formatting - should use raw values

Created on 15 January 2025, about 2 months ago

Problem/Motivation

Thank you so much for this wonderful and super helpful module to do quick and easy calculation on views.
I guess for English / US number formatting the module is working super well, but it looks like the module is calculating with formatted numbers instead of raw values, so the functionality is broken in other languages.

For example the German number format of
1 234.56 (EN)
is
1.234,56 (DE)
and there are a plenty of other number formattings.

Sadly, Drupals functionality for number formatting (also as view settings) is still poor, so you can't really fight well against these formats manually.

I created a Drupal Commerce Reports view, that outputs the sum of all orders in a month and then multiplies them wtih 0.01 for some internal calculations.

Workaround
In a related issue I found the workaround from @jrochate to use a global text field and twig to preprocess the values:
{{ fieldxyz|striptags|trim }}
( https://www.drupal.org/project/views_simple_math_field/issues/3134991#co... Pulling in rendered Views Field View content vs raw Active )

This works great to reverse the German number formatting hackish:
{{ amount|striptags|trim|replace({'.': '', ',': '.'}) }}

Maybe in a first step, this should be documents as workaround on the module page and in the README? But finally it would be great to always use the raw value.

Steps to reproduce

Set up a German Drupal project and create a Drupal Commerce Reports view like described above to reproduce the issue. Same for other languages with different number formats from the English (PHP decimals) defaults.

Proposed resolution

Always use raw values for calculations or add a setting to chose if the formatted or the raw value should be used
Just format the output of the calculation (already possible)

Remaining tasks

  • Discuss
  • Implement
  • Test
  • Release

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

Production build 0.71.5 2024