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
+3.5k Javascript : Detect when console is activated and do something about it
+5.5k Golang : Embedded or data bundling example
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+10.9k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+5.8k Golang : Pat multiplexer routing example
+4.7k Javascript : How to refresh page with JQuery ?
+16.4k How to enable MariaDB/MySQL logs ?
+14.9k Golang : Get file permission
+7k Golang : Add build version and other information in executables
+4.9k Golang : Find change in a combination of coins example
+9.1k Golang : cannot assign type int to value (type uint8) in range error
+11.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath