首页 > Web开发 > 详细

php 格式化金额

时间:2015-02-01 18:57:50      阅读:441      评论:0      收藏:0      [点我收藏+]
 1 /**
 2  * 格式化金额
 3  *
 4  * @param int $money
 5  * @param int $len
 6  * @param string $sign
 7  * @return string
 8  */
 9 function format_money($money, $len=2, $sign=‘¥‘){
10     $negative = $money > 0 ? ‘‘ : ‘-‘;
11     $int_money = intval(abs($money));
12     $len = intval(abs($len));
13     $decimal = ‘‘;//小数
14     if ($len > 0) {
15         $decimal = ‘.‘.substr(sprintf(‘%01.‘.$len.‘f‘, $money),-$len);
16     }
17     $tmp_money = strrev($int_money);
18     $strlen = strlen($tmp_money);
19     for ($i = 3; $i < $strlen; $i += 3) {
20         $format_money .= substr($tmp_money,0,3).‘,‘;
21         $tmp_money = substr($tmp_money,3);
22     }
23     $format_money .= $tmp_money;
24     $format_money = strrev($format_money);
25     return $sign.$negative.$format_money.$decimal;
26 }

 

php 格式化金额

原文:http://www.cnblogs.com/jackoogle/p/4265825.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!