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
+8.6k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.8k Golang : Find relative luminance or color brightness
+17k Golang : Find smallest number in array
+26.2k Golang : Force your program to run with root permissions
+7.1k Golang : Detect sample rate, channels or latency with PortAudio
+9.7k Golang : Test a slice of integers for odd and even numbers
+16.3k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+8.7k Golang : How to use Gorilla webtoolkit context package properly
+20.2k PHP : Convert(cast) int to double/float
+26.7k Golang : Convert CSV data to JSON format and save to file
+36k Golang : Convert(cast) int64 to string