Copy Code code as follows:
/**
* Format the number of
* Author:z,mingyu
Parameters
* Prmnum (number): Numbers to format
* PRMPTN (String): Formatting rules, such as: #,# #0.00
* * Prmnullvalue: The result returned when the number to be formatted is null, empty, or non-numeric. Default is 0
*/
function Formatnum (prmnum,prmptn,prmnullvalue) {
var nullvalue = Prmnullvalue? prmnullvalue:0;
if (Prmnum = = "" | | Prmnum = = null) return nullvalue;
Prmnum = Prmnum.replace (/\,/g, "");
if (isNaN (prmnum)) return nullvalue;
if (PRMPTN = = "" | | PRMPTN = = null) return prmnum;
var ptnlen = prmptn.length;
var pointindex = Prmptn.indexof (".");
var groupindex = Prmptn.indexof (",");
var Pointlen = (PointIndex = = 1 0:ptnlen-pointindex-1);
Prmnum = parsefloat (prmnum). toFixed (Pointlen) + "";
if (Groupindex!=-1) {
if (PointIndex = = 1) pointindex = Ptnlen;
var len = pointindex-groupindex-1;
var reg = new RegExp ("(-?\\d+) (\\d{" +len+ "})");
while (Reg.test (prmnum)) Prmnum = Prmnum.replace (Reg, "$1,$2");
}
return prmnum;
}