Home > php教程 > php手册 > body text

PHP保留两位小数并且四舍五入及不四舍五入的方法

WBOY
Release: 2016-06-13 12:47:52
Original
2753 people have browsed it

php保留两位小数并且四舍五入

复制代码 代码如下:


$num = 123213.666666;
echo sprintf("%.2f", $num);


php保留两位小数并且不四舍五入

复制代码 代码如下:


$num = 123213.666666;
echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2));


php进一法取整

复制代码 代码如下:


echo ceil(4.3); // 5
echo ceil(9.999); // 10


php舍去法,取整数

复制代码 代码如下:


echo floor(4.3); // 4
echo floor(9.999); // 9

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template