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...
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

franz’s picture

Another 2 possible solutions:

  • Do not use rendered tokens. Maybe use the same token names, but get raw values - bad if you are calculating over another math field.
  • Provide a parsed token for the field, which renders the number unformatted.
franz’s picture

Issue summary: View changes

Fixing formatting

Chris Matthews’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

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

Checking patch handlers/views_handler_field_math.inc...
error: while searching for:

  function render($values) {
    ctools_include('math-expr');
    $tokens = array_map('floatval', $this->get_render_tokens(array()));
    $value = strtr($this->options['expression'], $tokens);
    $expressions = explode(';', $value);
    $math = new ctools_math_expr;

error: patch failed: handlers/views_handler_field_math.inc:42
error: handlers/views_handler_field_math.inc: patch does not apply
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
996 bytes

Patch rerolled.