Closed (fixed)
Project:
Webform
Version:
7.x-4.0-alpha9
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 May 2012 at 13:34 UTC
Updated:
30 Aug 2014 at 13:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
quicksketchThanks, a good suggestion. PHP (and computers in general) certainly need little number massaging when dealing with odd numbers and division.
Comment #2
sah62 commentedI just ran into this same problem with the 7.x-3.18 release. This statement on line 565 in numbers.inc
fmod($element['#value'] - $starting_number, $element['#step']returns 0.0099999999999999 when $element['#value'] == 3.50, $starting_number == 0, and $element['#step'] == 0.01. I expected a result of 0.
Here's a custom function that returns correct results:
Comment #3
sah62 commentedThis issue still exists in 7.x-4.0-alpha8. Here's a patch.
Comment #4
quicksketchThanks @sah62! This needs to be applied everywhere, as it exists in all branches. Moving this to needs review to it will get picked up next time I'm going through the review queue.
Comment #5
sah62 commentedComment #6
quicksketchDoh, sorry @sah62. I went through the "easy" patches the past few weeks but missed this one. Next release. :)
Comment #7
sah62 commentedNo prob...
Comment #8
quicksketchI adjusted this patch to take the advice of this poster on PHP.net. This version uses ceil() or floor() based on if the number is negative for the proper modulo value when working with negative numbers.
Comment #9
quicksketchCommitted to all branches. Thanks guys!
Comment #10
sah62 commentedWorks for me - thanks!
Comment #12
superspring commentedGiven the webform_modulo code:
return $a - $b * (($b < 0) ? ceil($a / $b) : floor($a / $b));
If I try this with:
$a = 4.22
$b = 0.01
I get webform_modulo = 0.0099999999999998
and fmod = 0.0099999999999997
This appear to be an issue with PHP which this function does not resolve.
See var_dump(4.22-4.21);
Comment #13
aprogs commentedHi,
I have the same issue with Webform 4 RC3.
There is a number field with next validation settings:
When I'm trying to submit a form with value 8.6 I'm getting an error:
Comment #14
danchadwick commentedThere are two sources of this error. The first is that you can't compare floating points with the equal operator because of very small floating point rounding errors. The same routine used for fp comparisons in conditionals is used instead. The second is that due to fp rounding errors, the modulo function may return the modulus (e.g. 0.1 in the example), rather than 0. Both are explicitly tested for. To implement this I moved the fp comparison routine from conditionals.inc to number.inc.
Committed to 7.x-4.x and 8.x.