I have variable like this with the type of string: Now I tried setting it’s type to integer, so I tried these: So how to properly return the value 65000 as integer? Answer You wrong code, the first it’s correct and the second is intval($variable) I hope it’s just a typing error but in the va…
Tag: casting
Casting a value into FLOAT in PHP loses the decimal points. Basically turning the value into an INT
I’m calling a PHP form, the float value is received correctly, but if I cast it into a FLOAT, either immediately of afterwards, the value loses all decimal point numbers, and I don’t want that. I tried using floatval but same result. Answer Install proper locale settings on your machine. Probably …
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̵…
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 ?? Her…
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 &#…