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
+10.4k Golang : Create matrix with Gonum Matrix package example
+16.7k Golang : How to generate QR codes?
+35.7k Golang : Get file last modified date and time
+11k Golang : Simple image viewer with Go-GTK
+5.1k Golang : Print instead of building pyramids
+12.3k Elastic Search : Return all records (higher than default 10)
+16.9k Golang : How to save log messages to file?
+5.2k PHP : Hide PHP version information from curl
+13.8k Golang : Get current time
+10.4k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+8.7k Golang : Accept any number of function arguments with three dots(...)