Casting is a simple operation that can save many headaches. The code below show you how to cast a string into an float or integer with PHP.
// int example
$string_number = "72";
$float_number = (int) $string_number;
$string_number = "72";
$float_number = (int) $string_number;
// float example
$string_number = "324.75";
$float_number = (float) $string_number;
2 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE Related Posts
Read Full Article...
This code shows how to strip http, www, or any suffixes like .com or .co.uk etc. Read Full Article...
Read Full Article...
Here is another one:
Here is another one:
$x_string = “1.2e4″;
$x_float = $x_string * 1;
var_dump($x_float);
// Outputs float(12000)
Leave a Comment