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
+4.6k Golang : How to get capacity of a slice or array?
+16k Golang : Measure http.Get() execution time
+17.2k Golang : Reset or rewind io.Reader or io.Writer
+26.1k Golang : How to verify uploaded file is image or allowed file types
+11.5k Golang : How to determine if a year is leap year?
+8.2k Golang : Flip coin example
+4.4k Facebook : How to force facebook to scrape latest URL link data?
+16.2k Golang : Get host name or domain name from IP address
+3.1k Adding Skype actions such as call and chat into web page examples
+8.1k Golang : Get current, epoch time and display by year, month and day
+9.9k Golang : Convert(cast) float to int