Home > Backend Development > PHP Problem > How to convert float to int in php?

How to convert float to int in php?

Guanhui
Release: 2023-03-02 21:18:01
Original
4964 people have browsed it

How to convert float to int in php?

#How to convert float to int in php?

1. Use the function "intval" to convert float type data to int type;

$float = 15.222;
intval($float);
Copy after login

2. Use "settype()" to set float type data to int type;

$float = 15.222;
settype($float, 'int');
Copy after login

3. Add "(int)" in front of the variable to force it to int.

$float = 15.222;
(int) $float;
Copy after login

Recommended tutorial: "PHP"

The above is the detailed content of How to convert float to int in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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