小数点后保留两位,整数和小数通用
作者:互联网
toDemical(val) { let valNew = Math.round(parseFloat(val) * 100) / 100; let splitVal = valNew.toString().split("."); if (splitVal.length == 1) { valNew = valNew.toString() + ".00"; return valNew; } if (splitVal.length > 1) { if (splitVal[1].length < 2) { valNew = valNew.toString() + "0"; } return valNew; } }
标签:valNew,return,val,小数点,整数,length,toString,splitVal,小数 来源: https://www.cnblogs.com/florazeng/p/15930362.html