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
+12.4k Swift : Convert (cast) Int or int32 value to CGFloat
+22.9k Golang : Print out struct values in string format
+11.7k Golang : Convert a rune to unicode style string \u
+18.4k Unmarshal/Load CSV record into struct in Go
+7.4k Golang : Command line ticker to show work in progress
+6.4k Golang : Warp text string by number of characters or runes example
+17.5k Golang : Login and logout a user after password verification and redirect example
+4.9k Golang : Experimental Jawi programming language
+11.1k Golang : Delay or limit HTTP requests example
+4.7k Golang : Calculate a pip value and distance to target profit example