Math Expression displays wrong numbers for certain decimal values

Created on 6 May 2023, over 1 year ago

Problem/Motivation

The views_handler_field_math uses code copied from views_handler_field_numeric (this is even mentioned in a comment)
That code snippet has a bug due to limitations of PHP and float values: it produces wrong results for certain values.
This was fixed for numeric fields in issue #662692 β†’ only, but not applied to the same code used for Math expressions.

Steps to reproduce

Create any type of View with a display format using Fields.
Add a Global:Math Expression field and enter a decimal value in the Expression input field, e.g. 67.93 (the behaviour is only visible with certain values such as this example).
Don't check the Round checkbox.
Preview or display the View.
Instead of 67.93, the output will be 67.93000000000001

There is another bug:
Use any number between 0 and -1, e.g. -0.5.
Instead of -0.5, the output will be 0.5.

Proposed resolution

Backport the fix for Drupal8 in issue #1952926 β†’ (which fixes both issues) to both handlers, Numeric and Math Expression fields.

πŸ› Bug report
Status

Active

Version

3.29

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria alexh

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024