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
+17.9k Golang : Clearing slice
+16.8k Golang : Check if a directory exist or not
+10.3k Golang : GTK Input dialog box examples
+20.6k Golang : How to reverse slice or array elements order
+16.4k How to enable MariaDB/MySQL logs ?
+36k Golang : Read a text file and replace certain words
+13.4k Golang : Submit web forms without browser by http.PostForm example
+8.6k Golang : Load ASN1 encoded DSA public key PEM file example
+4.1k Golang : Display packages names during compilation
+7.6k Golang : Gaussian blur on image and camera video feed examples
+25k Golang : Convert file content into array of bytes
+29.5k Golang : bufio.NewReader.ReadLine to read file line by line