Home > Backend Development > PHP Tutorial > PHP怎么实现整除

PHP怎么实现整除

WBOY
Release: 2016-06-13 12:32:38
Original
1389 people have browsed it

PHP如何实现整除
http://www.zhixing123.cn/php/27277.html
如果我们使用’/'操作符进行除法运算时,如果遇到无法除尽的情况,会得到小数值。如果我只希望得到整数部分,怎么办呢?
在PHP的数学函数库里提供了多个函数供我们选择:
1、round函数, 对浮点数进行四舍五入。这个应该是最符合大家需要的吧。

<?php echo round(10/3); // 3
?> 
Copy after login


2、ceil函数, 进一法取整。
<?php echo ceil(4.3); // 5
?> 
Copy after login


3、floor ,舍去法取整,舍去小数部分
<?php echo floor(4.3); // 4
echo floor(9.999); // 9
?>
Copy after login
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