Skip to content
Advertisement

Tag: casting

String to Int shall throw instead of returning 0

If I cast a string with intval(‘string’) or with (int) ‘string’ and if that string contains letters other than numbers I get int 0 as result. Is there a way in which an catchable Exception is thrown, due to which I can check that the conversion was successful, so that the user can’t accidentally enter 1O instead of 10? Also

Cast a column as Boolean in PDO

I have a field (‘done’) in the Database which is boolean. The function which GET/ the rows doesn’t return a json with that field as boolean but it returns 1 or 0. How can I get THAT column (‘done’ column) as boolean? I mean, Is posible to cast a column with PDO::PARAM_BOOL ?? Here is my sample of UPDATE that

PHP unexpected result of float to int type cast

I’trying to convert a float to an int value in php: I can use ceil to make it work but can somebody explain this to me? Answer This is because numbers that have a finite representation in base 10 may or may not have an exact representation in the floating point representation PHP uses. See >php -r “echo var_dump(sprintf(‘%.40F’, 39.3

Advertisement