php实现四舍五入的方法小结
更新时间:2015年03月03日 11:58:38 作者:songguo
这篇文章主要介绍了php实现四舍五入的方法,实例总结了php实现四舍五入的三种常用方法,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例总结了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
2.round方法实现四舍五入
$number = 1234.5678; echo round($number ,2); //1234.57
3.sprintf 格式化输入实现四舍五入
$formatted = sprintf ("%s有¥%01.2f。",$name, $money); echo $formatted; //张三有¥123.10。
希望本文所述对大家的php程序设计有所帮助。
相关文章
ie与session丢失(新窗口cookie丢失)实测及解决方案
正如标题所言测试结果为:如果cookie设置是延后定时失效,而非进程级的,那在open后也能看到,所以,针对此情况,防止用户在使用ie内核出现登录状态丢失,可以配合cookie来使用2013-07-07php file_get_contents取文件中数组元素的方法
下面小编就为大家带来一篇php file_get_contents取文件中数组元素的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-04-04PHP运行出现Notice : Use of undefined constant 的完美解决方案分享
今天修改公司的网站,提示Notice : Use of undefined constant ,通过下面的方法解决了,最好是error_reporting(0);不需要更改配置2012-03-03
最新评论