PHP基本功之ceil,floor,round,intval

WBOY
Release: 2016-06-23 13:09:30
Original
1150 people have browsed it

ceil — 进一法取整

float ceil ( float $value )

返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。

echo ceil(4,3); //5

echo ceil(9.9); //10

floor — 舍去法取整

float floor ( float $value )

返回不大于 value 的下一个整数,将 value 的小数部分舍去取整。floor() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。

floor() 例子如图:

floor(4.3);//4


echo 'floor(4.3)='.floor(4.3).'<br>';echo 'floor(9.9)='.floor(9.9).'<br>';echo 'ceil(4.3)='.ceil(4.3).'<br>';echo 'ceil(9.9)='.ceil(9.9).'<br>';echo 'round(4.3)='.round(4.3).'<br>';echo 'round(9.9)='.round(9.9).'<br>';exit;
Copy after login

返回结果:

floor(4.3)=4
floor(9.9)=9
ceil(4.3)=5
ceil(9.9)=10
round(4.3)=4
round(9.9)=10

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!