Sharing of php formatted amount function, php amount function
The function of recent projects in handling funds is an indispensable function for the formatted output of RMB amounts. This function is relatively independent and popular, so it is convenient for everyone to encapsulate it into a function and send it up.
Copy code The code is as follows:
/**
* Format amount
*
* @param int $money
* @param int $len
* @param string $sign
* @return string
*/
function format_money($money, $len=2, $sign='¥'){
$negative = $money > 0 ? '' : '-';
$int_money = intval(abs($money));
$len = intval(abs($len));
$decimal = '';//Decimal
If ($len > 0) {
$decimal = '.'.substr(sprintf('%01.'.$len.'f', $money),-$len);
}
$tmp_money = strrev($int_money);
$strlen = strlen($tmp_money);
for ($i = 3; $i < $strlen; $i += 3) {
$format_money .= substr($tmp_money,0,3).',';
$tmp_money = substr($tmp_money,3);
}
$format_money .= $tmp_money;
$format_money = strrev($format_money);
Return $sign.$negative.$format_money.$decimal;
}
The above is the entire content of this article, I hope you all like it.
http://www.bkjia.com/PHPjc/951632.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951632.htmlTechArticleSharing of php formatted amount function, php amount function’s recent project has the function of processing funds, for RMB amount Formatted output is an essential feature. This function is quite unique...