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.2k Golang : Print how to use flag for your application example
+7.8k Swift : Convert (cast) String to Double
+18.2k Golang : Put UTF8 text on OpenCV video capture image frame
+12.3k Golang : Validate email address
+11.7k Golang : Secure file deletion with wipe example
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+17.7k How to enable MariaDB/MySQL logs ?
+6.7k Golang : Output or print out JSON stream/encoded data
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+36.3k Golang : Convert(cast) int64 to string
+10.1k Golang : Identifying Golang HTTP client request
+14k Golang : Google Drive API upload and rename example