php怎么四舍五入,php 四舍五入的三种实现方法
這篇文章主要為大家詳細(xì)介紹了php 四舍五入的三種實(shí)現(xiàn)方法,具有一定的參考價(jià)值,可以用來參考一下。
對(duì)php 四舍五入的三種方法感興趣的小伙伴,下面一起跟隨512筆記的小編兩巴掌來看看吧!
php 四舍五入的三種方法,分別通過number_format函數(shù)、round函數(shù)和sprintf格式化輸出的方法實(shí)現(xiàn)四舍五入
/**
* php 四舍五入的三種方法
*
* @param
* @arrange 512-筆記網(wǎng): www.512Pic.com
**/
//1.number_format 方法實(shí)現(xiàn)四舍五入
$number = 1234.5678;
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,57
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
//2.round方法實(shí)現(xiàn)四舍五入
$number = 1234.5678;
echo round($number ,2);
//1234.57
//3.sprintf 格式化輸入實(shí)現(xiàn)四舍五入
$formatted = sprintf ("%s有¥%01.2f。",$name, $money);
echo $formatted;
//張三有¥123.10。
/*** 來自512筆記(www.512pic.com) ***/
注:關(guān)于php 四舍五入的三種實(shí)現(xiàn)方法的內(nèi)容就先介紹到這里,更多相關(guān)文章的可以留意512筆記的其他信息。
關(guān)鍵詞:四舍五入
您可能感興趣的文章
總結(jié)
以上是生活随笔為你收集整理的php怎么四舍五入,php 四舍五入的三种实现方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 农业板块的龙头股票有哪些(农业龙头股票有
- 下一篇: php事件和行为,Yii框架组件和事件行