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

PHP中文网
Release: 2023-02-28 16:38:02
Original
9155 people have browsed it

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

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

intval(7/2)
Copy after login

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

ceil(7/2)
Copy after login

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

round(7/2)
Copy after login

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

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

4,向下取整

floor(7/2)
Copy after login

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

相关文章:

PHP四舍五入函数代码详解

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

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

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

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!