1.两位小数字输出,超过两位保持不动
function formmatData(val) { if (val) { if (val.toString().split(".")[1]) { return val.toString().split(".")[1].length == 2 ? val.toString() : val.toString() + "0"; } else { return val.toString() + ".00"; } } } console.log(formmatData(3434.3)); //3434.30 console.log(formmatData(141.44)); //141.44 console.log(formmatData(141));//141.00 console.log(formmatData(141.5466126)); //141.54661260