Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP Casting Strings and Floats to Integers

<?php
// Converting float to integer
$x = 23.72;
$float_int = (int)$x;
echo $int_cast;
/* This outputs 23. From this, we observe that the floor is calculated of the
float and not rounding or ceiling of the float*/

echo "<br>";

// Converting string to integer
$x = "62.924";
$int_cast = (int)$x;
echo $int_cast;
/* This outputs 62. From this, we observe that the floor is calculated of the
float and not the rounded number or ceiling of the string*/
// Converting string to integer
$x = "Text";
$int_cast = (int)$x;
echo $int_cast;
/* This outputs 0. From this, we observe that if the string contains text, 
it outputs*/
?>
Comment

PREVIOUS NEXT
Code Example
Php :: if name value contains space in php 
Php :: echo query in laravel 
Php :: create session in wordpress 
Php :: php reindex array after unset 
Php :: how to start a session 
Php :: php get filename without extension 
Php :: wordpress get post author link 
Php :: replace _ with space php 
Php :: codeigniter 4 pagination descending 
Php :: get hours difference between two dates in php 
Php :: guzzle http try catch 
Php :: get_template_part parameters 
Php :: in_array in php 
Php :: laravel vendor publish all files 
Php :: convert date in php 
Php :: php get age from dob 
Php :: wp-config.php define home page 
Php :: wordpress custom fields variable dump 
Php :: laravel request validation boolean 
Php :: show php info 
Php :: php artisan make:request 
Php :: Interval Between Different Dates 
Php :: save error cakephp 2 
Php :: remove slashes from json php 
Php :: if is checkout page woocommerce 
Php :: php header base64 pdf 
Php :: laravel end date greater than start date validation 
Php :: get youtube thumbnail php 
Php :: How can I prevent SQL injection in PHP? 
Php :: php get precent price 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =