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
+6.2k Golang : Of hash table and hash map
+14.5k Golang : How to reverse elements order in map ?
+4.4k Golang : If else example and common mistake
+6k Golang : Squaring elements in array
+11k Golang : Add ASCII art to command line application launching process
+12.4k Golang : Convert spaces to tabs and back to spaces example
+25.8k Golang : Convert CSV data to JSON format and save to file
+12.9k Golang : Convert IP version 6 address to integer or decimal number
+7.3k Golang : How to check variable or object type during runtime?
+37.8k Golang : Remove dashes(or any character) from string
+4.5k Swift : Convert string array to array example
+10.3k Golang : How to flush a channel before the end of program?