Home > Backend Development > PHP Tutorial > php实现四舍五入的方法小结_PHP

php实现四舍五入的方法小结_PHP

WBOY
Release: 2016-05-31 13:16:41
Original
808 people have browsed it

本文实例总结了php实现四舍五入的方法。分享给大家供大家参考。具体分析如下:

php实现四舍五入的三种方法,分别通过number_format函数、round函数和sprintf格式化输出的方法实现四舍五入

1.number_format 方法实现四舍五入

$number = 1234.5678; 
$nombre_format_francais = number_format($number, 2, ',', ' '); 
// 1 234,57 
$english_format_number = number_format($number, 2, '.', ''); 
// 1234.57 
Copy after login

2.round方法实现四舍五入

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

3.sprintf 格式化输入实现四舍五入

$formatted = sprintf ("%s有¥%01.2f。",$name, $money); 
echo $formatted;   
//张三有¥123.10。
Copy after login

希望本文所述对大家的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