PHP : Convert(cast) int to double/float
Tags : convert casting int float double php
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
Tags : convert casting int float double php
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
+1.6k Golang : Warp text string by number of characters or runes example
+1.2k Golang : Reverse text lines or flip line order example
+1.7k Python : Convert(cast) bytes to string example
+9.9k Golang : Round float to precision example
+3.2k Golang : Check if user agent is a robot or crawler example
428 Golang : Calculate a pip value and distance to target profit example
+13.5k Golang : Convert(cast) string to rune and back to string example
+3.1k Golang : Take screen shot of browser with JQuery example
+1k Golang : Find the shortest line of text example
+12.5k Golang : For loop continue,break and range
+2.6k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+3.4k Golang : Convert(cast) bigint to string