// 转换数值类型toNumber(str, dec =1){const r =parseFloat(str)if(isNaN(r)){return0}else{returnparseFloat(r.toFixed(dec))}},
// 保留0位小数(结果是字符型),页面显示的时候使用toDecStr0(str){// 异常值判断if(str ===null|| str === undefined || str ===''|| str ===' ')return'-'const r =parseInt(str)if(isNaN(r)){return'-'}else{return r
}},
// 保留一位小数(结果是字符型),页面显示的时候使用toDecStr1(str, trim0 =true){// 异常值判断if(str ===null|| str === undefined || str ===''|| str ===' ')return'-'const dec =1const r =parseFloat(str)if(isNaN(r)){return'-'}else{let res = r.toFixed(dec)if(trim0 ===false){return res
}// 删除尾部的‘0’if(res.endsWith('0')){
res = res.substring(0, res.lastIndexOf('0'))}// 删除尾部的‘.’if(res.endsWith('.')){
res = res.substring(0, res.lastIndexOf('.'))}return res
}},
// 保留两位小数(结果是字符型),页面显示的时候使用toDecStr2(str, trim0 =true){// 异常值判断if(str ===null|| str === undefined || str ===''|| str ===' ')return'-'const dec =2const r =parseFloat(str)if(isNaN(r)){return'-'}else{let res = r.toFixed(dec)if(trim0 ===false){return res
}// 删除尾部的‘0’if(res.endsWith('00')){
res = res.substring(0, res.lastIndexOf('0')-1)}elseif(res.endsWith('0')){
res = res.substring(0, res.lastIndexOf('0'))}// 删除尾部的‘.’if(res.endsWith('.')){
res = res.substring(0, res.lastIndexOf('.'))}return res
}},
// 保留三位小数(结果是字符型),页面显示的时候使用toDecStr3(str, trim0 =true){// 异常值判断if(str ===null|| str === undefined || str ===''|| str ===' ')return'-'const dec =3const r =parseFloat(str)if(isNaN(r)){return'-'}else{let res = r.toFixed(dec)if(trim0 ===false){return res
}// 删除尾部的‘0’if(res.endsWith('000')){
res = res.substring(0, res.lastIndexOf('0')-2)}elseif(res.endsWith('00')){
res = res.substring(0, res.lastIndexOf('0')-1)}elseif(res.endsWith('0')){
res = res.substring(0, res.lastIndexOf('0'))}// 删除尾部的‘.’if(res.endsWith('.')){
res = res.substring(0, res.lastIndexOf('.'))}return res
}}