diff --git a/src/IntType.php b/src/IntType.php index 05f08df..404ef47 100644 --- a/src/IntType.php +++ b/src/IntType.php @@ -17,7 +17,7 @@ final public static function from( return (int) $value; } - if (Validators::isNumeric($value) && (int) $value === (int) \ceil(\abs((float) $value))) { + if (Validators::isNumeric($value) && \abs((int) $value) === (int) \ceil(\abs((float) $value))) { return (int) $value; } diff --git a/tests/IntTypeTest.phpt b/tests/IntTypeTest.phpt index fc2e376..df218ff 100644 --- a/tests/IntTypeTest.phpt +++ b/tests/IntTypeTest.phpt @@ -45,6 +45,9 @@ final class IntTypeTest extends TestCase '1', 1.000_00, '1.00000', + -1, + -1.0, + '-1.0', ]; foreach ($invalid as $value) {