Php formatted amount

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.