Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I bumped into this issue some days ago. The short for it:
- Setup a couple of fields to display number values. Use different formatting for thousands separator (like a dot)
- Setup a math field, calculate something from the values above.
- Basically, floatval() expects non-localized numbers and will parse the wrong numbers.
The possible solutions:
- Add the source numbers as unformatted. This is probably the suggested way of doing, but it's not good if you also want to display the values. Then you need to duplicate it, hide the unformatted. Then if someone else edits the view and wants to change it, will have to figure out that both fields need to be changed... If someone else wants to add another field. Also, not to mention this is non-obvious and non-documented.
- Replace the token values before running floatval(). This is my approach in the patch attached. The issue then would be which values to replace. I used in this patch the options configured for the math field itself, as it was faster and kept it consistent. Still not sure if it is the best way of doing, but for someone working on localized numbers, it all works as expected...
Comment | File | Size | Author |
---|---|---|---|
#3 | views-math_localized_numbers-1839222-3.patch | 996 bytes | Andrew Answer |
|
Comments
Comment #1
franzAnother 2 possible solutions:
Comment #1.0
franzFixing formatting
Comment #2
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 6 year old patch to views_handler_field_math.inc does not apply to the latest views 7.x-3.x-dev and if still applicable needs to be rerolled.
Comment #3
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.