Home  >  Article  >  Backend Development  >  How to convert integer to decimal in php

How to convert integer to decimal in php

王林
王林Original
2020-09-29 09:57:223354browse

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.

How to convert integer to decimal in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn