: This article mainly introduces the php formatting amount. if you are interested in the PHP Tutorial, you can refer to it.
1/** 2 * format the amount 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 = ''; // 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}
The above introduces the php formatting amount, including the content, and hopes to help friends who are interested in the PHP Tutorial.