If you want to display the currency data in a certain form on the page, you must first format it. The following describes the specific formatting code. If you are interested, refer
The Code is as follows:
Function formatCurrency (num ){
Var sign = "";
If (isNaN (num ))
{
Num = 0;
}
If (num <0)
{
Sign = "-";
}
Var strNum = num + "";
Var arr1 = strNum. split (".");
Var hasPoint = false; // whether the fractional part exists
Var piontPart = ""; // fractional part
Var intPart = strNum; // integer part
If (arr1.length> = 2)
{
HasPoint = true;
PiontPart = arr1 [1];
IntPart = arr1 [0];
}
Var res = ''; // Save the part with a comma
Var intPartlength = intPart. length; // integer part length
Var maxcount = Math. ceil (intPartlength/3); // you need to add several commas to the integer part.
For (var I = 1; I <= maxcount; I ++) // Add a comma for each three digits
{
Var startIndex = intPartlength-I * 3; // start position
If (startIndex <0) // when the start position is smaller than 0, the value is 0.
{
StartIndex = 0;
}
Var endIndex = intPartlength-I * 3 + 3; // end position
Var part = intPart. substring (startIndex, endIndex) + ",";
Res = part + res;
}
Res = res. substr (0, res. length-1); // remove the last comma
If (hasPoint)
{
Return "¥" + sign + res + "." + piontPart;
}
Else
{
Return "¥" + sign + res;
}
}