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
+22.3k Generate checksum for a file in Go
+13.7k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+19.2k Golang : Get current URL example
+31.5k Golang : Convert an image file to []byte
+10.3k Golang : Select region of interest with mouse click and crop from image
+5.5k Get website traffic ranking with Similar Web or Alexa
+6.8k Restart Apache or Nginx web server without password prompt
+5.8k Golang : Grab news article text and use NLP to get each paragraph's sentences
+15.3k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+14.5k Golang : Find commonalities in two slices or arrays example
+17.4k Golang : Read data from config file and assign to variables
+18.4k Golang : Set, Get and List environment variables