Examples are as follows:
/**
* Digital format converts thousands of decimal places
* @param {object}num */
function Commafy (num) {
if (num+ ""). Trim () = = "") {return
"";
}
if (isNaN (num)) {return
"";
}
num = num+ "";
if (/^.*\.. *$/.test (num)) {
Varpointindex =num.lastindexof (".");
Varintpart = num.substring (0,pointindex);
Varpointpart =num.substring (pointindex+1,num.length);
Intpart = Intpart + "";
var re =/(-?\d+) (\d{3})/While
(Re.test (Intpart)) {
Intpart =intpart.replace (Re, "$1,$2")
}
num = Intpart+ "." +pointpart;
} else{
num = num + "";
var re =/(-?\d+) (\d{3})/While
(Re.test (num)) {
num =num.replace (Re, ' $1,$2 ')
}
return
num ;
}
/**
*
@param {object}num * * *
function Delcommafy (num) {
if (num+ "). Trim () = = "") {return
"";
}
Num=num.replace (/,/gi, "");
Returnnum;
}
The above JS implementation of the digital format of the thousand-point mutual conversion method is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.