Skip to content

Commit 9877134

Browse files
authored
Fix bug when using multipleOf values with decimal places
1 parent e913512 commit 9877134

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Schema/Type/Number.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function validate(mixed $value, callable $fail): void
5050
}
5151
}
5252

53-
if ($this->multipleOf !== null && $value % $this->multipleOf !== 0) {
53+
// Divide the value by multipleOf instead of using the modulo operator to avoid bugs when using a multipleOf
54+
// that has decimal places. (Since the modulo operator converts the multipleOf to int)
55+
if ($this->multipleOf !== null && $value/$this->multipleOf !== (float) round($value/$this->multipleOf)) {
5456
$fail(sprintf('must be a multiple of %d', $this->multipleOf));
5557
}
5658
}

0 commit comments

Comments
 (0)