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 }