PHP : Convert(cast) int to double/float
Problem :
You have an integer value and you need to convert it ot double or float value in PHP
Solution :
Use the number_format function to cast the integer to float value. For example :
<?php
$integer = 2;
echo $integer.'<br>';
$float = number_format($integer,3); // up to 3 decimals
echo $float.'<br>';
?>
See also : PHP : Convert(cast) string to bigInt
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+36.1k Golang : How to split or chunking a file to smaller pieces?
+13.1k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+33.7k Golang : convert(cast) bytes to string
+5.9k Fontello : How to load and use fonts?
+13.8k Golang : Get current time
+7k Golang : Gorrila mux.Vars() function example
+15k Golang : How to check if IP address is in range
+8.1k Swift : Convert (cast) Character to Integer?
+21.9k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+20k Golang : How to get own program name during runtime ?
+15.8k Golang : Get file permission
+7.4k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image