[php-src] Issue #7950: preg_match fails to match zero
| From: | iluuu1994 | Date: | Sun, 16 Jan 2022 00:00:57 +0000 |
| Subject: | [php-src] Issue #7950: preg_match fails to match zero | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239033@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7950
Comment Author: iluuu1994
As @KapitanOczywisty mentioned, the reason
preg_match fails is because it is a string
operation and implicitly coerces 0.0 to the string "0". Both
"0" and "0.0" could be valid string representations of
the float 0.0 but PHP can't know which one you might want and thus always does the
former. The solution for you is to either:
* Make the fractional part optional (as suggested in the last comment)
* Convert the float to a uniform string that always has the fractional part
* Calculate the parts using arithmetic operations instead of string parsing