Home > Backend Development > PHP Problem > How to convert integer to decimal in php

How to convert integer to decimal in php

王林
Release: 2023-03-06 09:10:02
Original
3372 people have browsed it

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 )
Copy after login

Code example:

<?php
$a = 26;
$b = 4;
$a/=$b;
echo intval($a);//6
echo floatval($a);//6.5
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template