diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 39f8663da167..e5d3f9dc2bc1 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1267,7 +1267,11 @@ public function validateMultipleOf($attribute, $value, $parameters) return false; } - return fmod($value, $parameters[0]) === 0.0; + if ((float) $parameters[0] === 0.0) { + return false; + } + + return bcmod($value, $parameters[0], 16) === '0.0000000000000000'; } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 215cf431c122..9b2a96d3591e 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1912,18 +1912,21 @@ public function multipleOfDataProvider() [5.0, -10, false], [10.5, 10.5, true], // float (same) [10.5, 0.5, true], // float + float - [10.5, 0.3, false], + [10.5, 0.3, true], // 10.5/.3 = 35, tricky for floating point division [31.5, 10.5, true], [31.6, 10.5, false], [10.5, -0.5, true], // float + -float - [10.5, -0.3, false], + [10.5, -0.3, true], // 10.5/.3 = 35, tricky for floating point division [-31.5, 10.5, true], [-31.6, 10.5, false], [-10.5, -10.5, true], // -float (same) [-10.5, -0.5, true], // -float + -float - [-10.5, -0.3, false], + [-10.5, -0.3, true], // 10.5/.3 = 35, tricky for floating point division [-31.5, -10.5, true], [-31.6, -10.5, false], + [2, .1, true], // fmod does this "wrong", it should be 0, but fmod(2, .1) = .1 + [.75, .05, true], // fmod does this "wrong", it should be 0, but fmod(.75, .05) = .05 + [.9, .3, true], // .9/.3 = 3, tricky for floating point division ['foo', 1, false], // invalid values [1, 'foo', false], ['foo', 'foo', false],