JS formatting amount, whether to choose whether to bring a thousand points, optional retaining accuracy, which is also found online, but the use is fine
Copy code code as follows:
/*
Format the value after entering the five houses.
@Param NUM value (Number or String)
@param Center to be retained
@Param Isthousand, do you need a thousand points 0: No need, 1: need (numerical type);
@Return format string, such as '1,234,567.45'
@Type String
*/
Function Formatnumber (NUM, Cent, Isthousand) {{
num = num.tostring (). Replace (// $ |/,/g, '');
if (isnan (num)) // Check the number of intake values for numerical types.
num = "0";
If (ISNAN (Cent)) // Make sure that the small number is introduced to the value type value.
center = 0;
Center = PARSEINT (center);
center = math.abs (center); // Find a decimal digit to ensure that it is a positive integer.
If (ISNAN (ISTHOUSAND)) // Make sure whether it is required to be passed into a thousand points into numerical types.
Isthousand = 0;
iStHousand = PARSEINT (Isthousand);
if (Isthousand <0)
Isthousand = 0;
If (Isthousand> = 1) // Make sure the intake value is only 0 or 1
Isthousand = 1;
sign = (num == (num = math.abs (num)); // Get the symbol (positive/negative)
//Math.floor: Returns the maximum integer that is less than equal to its numerical parameters
num = math.floor (num*math.pow (10, center) +0.50000000001); // convert the specified decimal bit into an integer. The extra decimal bits are four and five.
center = num%math.pow (10, center); // Find a decimal digit value.
num = math.floor (num/math.pow (10, center)). Tostring (); // Find an integer digit value.
ques = center.tostring (); // convert the decimal bits into a string to find the length of the decimal.
While (central.Length <Cent) {// Make up the number to the specified digits.
center = "0" + center;
}
if (iStHousand == 0) // No need thousands of quota.
Return ((sign)? '': '-') + num + '.' + CentS);
// Format the integer part for thousands of points.
for (var I = 0; I <math.floor ((num.length- (1+i))/3); i ++)
NUM = NUM.Substring (0, NUM.LENGTH- (4*I+3))+'+
num.substring (num.length- (4*i+3));
Return ((sign)? '': '-') + num + '.' + CentS);
}