When I use this :
preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', 0.0001);
The return value is 1, and when I use this :
preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', 0.00001);
The return value is 0.
Somebody could say me why please ? Thanks !
Because small floating point numbers are normally displayed using exponential notation, so 0.00001 is converted to 1.0E-5, which doesn't match the regexp. You can see this if you simply do:
echo 0.00001;
Regular expressions should be used with strings, not numbers.
preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', '0.00001');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With