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
+11.7k Golang : Convert IPv4 address to packed 32-bit binary format
+5.3k Golang : Test input string for unicode example
+14.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+13.9k Golang : Find location by IP address and display with Google Map
+14k Golang : Get digits from integer before and after given position example
+11.2k Golang : Listen and Serve on sub domain example
+4.1k Golang : micron to centimeter example
+9.4k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+19.2k Golang : Underscore or snake_case to camel case example
+9.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+5.5k Golang : Find the longest line of text example
+21.7k Golang : Randomly pick an item from a slice/array example