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
+17.2k Golang : How to generate QR codes?
+9.5k Golang : Temperatures conversion example
+6.9k Golang : Humanize and Titleize functions
+16k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+6.2k Golang : Missing Subversion command
+5.4k Python : Create Whois client or function example
+6.5k Golang : Detect face in uploaded photo like GPlus
+7.5k Golang : How to fix html/template : "somefile" is undefined error?
+10.4k Golang : How to profile or log time spend on execution?
+12.5k Golang : How to display image file or expose CSS, JS files from localhost?
+8.5k Golang: Prevent over writing file with md5 hash