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
+13.6k Golang : Strings comparison
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+5.8k Linux : Disable and enable IPv4 forwarding
+9.9k Golang : Convert octal value to string to deal with leading zero problem
+8.1k Golang : How To Use Panic and Recover
+10.6k Golang : How to delete element(data) from map ?
+21.2k Golang : How to force compile or remove object files first before rebuild?
+5.9k Unix/Linux : How to open tar.gz file ?
+14.6k Golang : Convert(cast) int to float example
+6.7k Golang : Check if password length meet the requirement
+24k Golang : Find biggest/largest number in array