|
// 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;
} |