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

How to convert value to integer in php

青灯夜游
青灯夜游Original
2022-02-11 18:37:523517browse

Method: 1. Add "(int)" or "(integer)" before the value, for example "3.14(int)"; 2. Use the intval() function, the syntax is "intval(value)" ;3. Use the ceil() function, the syntax is "ceil(value)"; 4. Use the floor function, the syntax is "floor(value)".

How to convert value to integer in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php transfers the value For an integer

1, add "(int)" or "(integer)" before the value

";

$float = 3.14;
$int = (integer)$float;
echo $int."
"; ?>

How to convert value to integer in php

2. Use the intval() function

";

$float = 5.64;
$int = intval($float);
echo $int."
"; $bool = true; $int = intval($bool); echo $int."
"; ?>

How to convert value to integer in php

##3. Use the ceil() function

ceil() function is used to round up. If there is a decimal, add 1 to the integer part

';
echo $int;
?>

How to convert value to integer in php

4. Use the floor function

floor function is used to round down

';
echo $int;
?>

How to convert value to integer in php

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of How to convert value to integer 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