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
+5.1k Golang : Convert source code to assembly language
+13.2k Golang : Check whether a network interface is up on your machine
+4.9k Golang : Normalize email to prevent multiple signups example
+5.8k Golang : Get today's weekday name and calculate target day distance example
+35.7k Golang : Marshal and unmarshal json.RawMessage struct example
+5.6k Golang : Routes multiplexer routing example with regular expression control
+8.3k Golang : Decompress zlib file example
+3.8k Golang : Dealing with backquote
+18.3k Generate checksum for a file in Go
+6.4k Golang : does not implement flag.Value (missing Set method)
+12.6k Golang : Calculate entire request body length during run time
+17.8k Golang : How to read JPG(JPEG), GIF and PNG files ?