Re: variable type - conversion/checking
| From: | Maciek Sokolewicz | Date: | Sun, 17 Mar 2013 21:20:58 +0000 |
| Subject: | Re: variable type - conversion/checking | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320620@lists.php.net to get a copy of this message | ||
On 16-3-2013 19:20, Matijn Woudt wrote:
On Sat, Mar 16, 2013 at 6:52 PM, Maciek Sokolewicz < maciek.sokolewicz@gmail.com> wrote:So as a result, the input could always be interpreted as an integer, without any precision-loss using the method above. - TulHi,Wrong. is_numeric will accept 1e1, which is a float, so you would need to check for e or E too. - Matijn Although in theory I agree, indeed any e* number is treated as a floating point number. However, considering the exponent and the base are forced to be integer numbers (due to exclusion of decimal points), in the real number system, you will *always* end up with a natural number, i.e. integer. Regardless of your input.I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georgAll responses in this thread have been very nice; but you could also try a much simpler 2-step check: 1. is_numeric 2. if true > check if there's a decimal character in the string: if(is_numeric($str) && false === strpos('.', $str)) {// it's an int for sure} else {// might be a number, but it's definitly not an int}