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
+18.4k Golang : How to get hour, minute, second from time?
+26.4k Golang : Calculate future date with time.Add() function
+17.5k Golang : Check if IP address is version 4 or 6
+5.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+6.6k Golang : Spell checking with ispell example
+16.4k Golang : Find out mime type from bytes in buffer
+9.1k Golang : Build and compile multiple source files
+10.4k Golang : How to check if a website is served via HTTPS
+24.6k Golang : Time slice or date sort and reverse sort example
+26.5k Golang : Get executable name behind process ID example
+22.2k Golang : Repeat a character by multiple of x factor
+14k Golang : How to check if a file is hidden?