Home  >  Article  >  Backend Development  >  php 数据处理之四舍五入取整实现4种方法

php 数据处理之四舍五入取整实现4种方法

PHP中文网
PHP中文网Original
2017-06-02 23:56:199109browse

本文介绍php四舍五入函数使用方法,php 数据处理之取整,四舍五入分为四个部分,php四舍五入函数使用分别如下。

1.丢弃小数部分,保留整数部分  

intval(7/2)

2.向上取整,有小数就整数部分加1  

ceil(7/2)

3, 对浮点数进行四舍五入  

round(7/2)

如果php四舍五入要保留两位小数,后来参数根保留小数位数即可。

$number = 1234.5678;
echo round($number ,2); //1234.57

4,向下取整  

floor(7/2)

以上是PHP中文网为您介绍的php 数据处理之取整,四舍五入的方法,更多相关文章请访问本文其它技术文章!

相关文章:

PHP四舍五入函数代码详解

php中四舍五入取整函数详细介绍

PHP实现四舍五入的3种方法

php四舍五入截取浮点型字符串方法总结

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