There are four rounding functions in PHP, such as floor, ceil, round, and intval. Below, I will introduce application examples of each of them.
floor rounding by rounding Syntax format: float floor (float value)
Returns the next integer not greater than value, and rounds the decimal part of value. The type returned by floor() is still float because the range of float values is usually larger than that of integer.
The code is as follows
代码如下 |
复制代码 |
echo floor(4.3); // 4
echo floor(9.999); // 9
|
|
Copy code
|
echo floor(4.3); // 4
echo floor(9.999); // 9
代码如下 |
复制代码 |
echo ceil(4.3); // 5
echo ceil(9.999); // 10 |
ceil round to the nearest integer Syntax format: float ceil (float value)
Returns the next integer that is not less than value. If value has a decimal part, it is rounded up by one. The type returned by ceil() is still float, because the range of float values is usually larger than that of integer
代码如下 |
复制代码 |
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
|
The code is as follows
|
Copy code
echo ceil(4.3); // 5
echo ceil(9.999); // 10
代码如下 |
复制代码 |
echo intval(4.3); //4
echo intval(4.6); // 4
?>
|
| round Rounds floating point numbers
|
Syntax: float round ( float val [, int precision] )
The code is as follows
Copy code
|
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
intval---convert variables into integer types
Example intval()
The code is as follows
|
Copy code
|
<🎜>echo intval(4.3); //4<🎜>
<🎜>echo intval(4.6); // 4 <🎜>
<🎜>?>
http://www.bkjia.com/PHPjc/632727.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632727.htmlTechArticleThere are four rounding functions in php, such as floor, ceil, round, intval. Below I will introduce application examples between them. floor is rounded by rounding. Grammar format: float fl...
|
|
|
|
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