Php fund format conversion function _ PHP Tutorial

Source: Internet
Author: User
Php fund format conversion function. This article introduces a self-defined Fund conversion function, which can be converted into a bank format based on user input. if you need this function, you can refer to it. The following code is used to copy the code. This document describes a custom fund conversion function. you can convert the function to a bank-format fund format based on your input. if you need it, refer to it.
The code is as follows:

// Function name: ExchangeMoney ($ N_money)

// For use: capital conversion function

// Parameter: $ N_money (number of the amount to be converted)

// Return value: string

// Standby note: This function example: $ char = ExchangeMoney (5645132.3155) ==>$ char = '¥ 5,645,132.31'

// Configure //-----------------------------------------------------------------------------------

Function ExchangeMoney ($ N_money)

{

$ A_tmp = explode (".", $ N_money); // divide the number into two parts by the decimal point, and store the array $ A_tmp

$ I _len = strlen ($ A_tmp [0]); // measure the width of the digits before the decimal point.

If ($ I _len % 3 = 0)

{

$ I _step = $ I _len/3; // for example, the width of the previous digit mod 3 = 0, which can be divided into $ I _step

} Else

{

$ Step = ($ len-$ len % 3)/3 + 1; // for example, the width of the previous digit mod 3! = 0, which can be divided into $ I _step + 1

}

$ C_cur = "";

// Convert the amount before the decimal point

While ($ I _len <> 0)

{

$ I _step --;

If ($ I _step = 0)

{

$ C_cur. = substr ($ A_tmp [0], 0, $ I _len-($ I _step) * 3 );

} Else

{

$ C_cur. = substr ($ A_tmp [0], 0, $ I _len-($ I _step) * 3 ).",";

}

$ A_tmp [0] = substr ($ A_tmp [0], $ I _len-($ I _step) * 3 );

$ I _len = strlen ($ A_tmp [0]);

}

// Convert the amount after the decimal point

If ($ A_tmp [1] = "")

{

$ C_cur. = ". 00 ";

} Else

{

$ I _len = strlen ($ A_tmp [1]);

If ($ I _len <2)

{

$ C_cur. = ".". $ A_tmp [1]. "0 ";

} Else

{

$ C_cur. = ".". substr ($ A_tmp [1], 0, 2 );

}

}

// Add and transfer the RMB symbol

$ C_cur = "¥". $ C_cur;

Return $ C_cur;

}

Bytes. The code is as follows...

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.