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.
Comments
Comment #2
damienmckennaThanks for raising this.
Have you looked at some of the other issues related to the math field? e.g. #2451775: View handler field math expression - Unformat token value before evaluating expression., #2263079: Suppress division by zero error in global math expression or #1839222: Global: Math + localized numbers in tokens.?