Home >Backend Development >PHP Problem >How to convert integer to decimal in php
php method to convert integers to decimals: You can use the floatval() function to perform the conversion, such as [floatval($a);]. The floatval() function is used to obtain the floating point value of a variable. It should be noted that this function cannot be used for arrays or objects.
Function introduction:
floatval function is used to obtain the floating point value of a variable. floatval cannot be used with arrays or objects.
(Recommended tutorial: php video tutorial)
Grammar format:
float floatval ( mixed $var )
Code example:
<?php $a = 26; $b = 4; $a/=$b; echo intval($a);//6 echo floatval($a);//6.5 ?>
Related recommendations: phptraining
The above is the detailed content of How to convert integer to decimal in php. For more information, please follow other related articles on the PHP Chinese website!