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

How to convert float to int in php?

Guanhui
Guanhui Original
2020-07-22 11:28:40 4837browse

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);

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

$float = 15.222; settype($float, 'int');

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

$float = 15.222; (int) $float;

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!

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