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
+8.9k Android Studio : Simple input textbox and intercept key example
+5.1k Golang : Detect face in uploaded photo like GPlus
+5.3k CodeIgniter : form input set_value cause " to become & quot
+6.5k Golang : Convert source code to assembly language
+13.6k Golang : Get all local users and print out their home directory, description and group id
+13.7k Golang : How to check for empty array string or string?
+5.6k Golang : Warp text string by number of characters or runes example
+24.5k Mac/Linux and Golang : Fix bind: address already in use error
+7.5k Linux/Unix : fatal: the Postfix mail system is already running
+6.7k Golang : Get today's weekday name and calculate target day distance example
+11.9k Golang : Get user input until a command or receive a word to stop
+5.3k Grep : How to grep for strings inside binary data