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
+19.1k Mac OSX : Homebrew and Golang
+5.7k Linux/Unix/PHP : Restart PHP-FPM
+12.8k Golang : Get terminal width and height example
+8.7k Golang : Take screen shot of browser with JQuery example
+12.6k Golang : zlib compress file example
+9.2k Golang : Generate random Chinese, Japanese, Korean and other runes
+4.6k Unix/Linux : How to pipe/save output of a command to file?
+6.1k Golang : Calculate US Dollar Index (DXY)
+33.8k Golang : Call a function after some delay(time.Sleep and Tick)
+21.5k Golang : GORM create record or insert new record into database example
+17.1k Golang : When to use init() function?
+8.8k Golang : Gaussian blur on image and camera video feed examples