zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

Bug with the Step validator #215

Closed biserantonov closed 5 years ago

biserantonov commented 6 years ago

Step validator is not working properly. For example if I set baseValue = 50 and step = 0.01 then the validation fails for the value of 50.09, which is perfectly valid. I think the problem is in the calculation of the fmod:

$fmod = $this->fmod($value - $this->baseValue, $this->step);

In this example $value - $this->baseValue == 0.090000000000003 and then $fmod == 3.41E-15. Maybe it the fmod is rounded to the precision of the step the issue will be fixed.

I'm using PHP 5.6.33

Ocramius commented 6 years ago

Requires a test case

codisart commented 6 years ago

Hi @Ocramius and @froschdesign,

I added some unit tests to prove the bug pull request You can see the travis build