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
+9.8k Golang : Replace a parameter's value inside a configuration file example
+15.7k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+11.7k Golang : Sort and reverse sort a slice of bytes
+28.3k Golang : JQuery AJAX post data to server and send data back to client example
+10k PHP : Convert(cast) bigInt to string
+2.3k Golang : Fix go-cron set time not working issue
+8.7k Golang : Copy map(hash table) example
+18.8k Golang : Compare floating-point numbers
+15k Golang : Generate universally unique identifier(UUID) example
+8.4k Golang : How to control fmt or log print format?
+3.7k Java : Generate multiplication table example