js 格式化数字保留2位小数
function toDecimal2(x) { var f = parseFloat(x); if (isNaN(f)) { return false; } var f = Math.round(x*100)/100; var s = f.toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } return s; } //-------调用 var val; val=obj[i].value.replace('[',''); val=val.replace(']',''); var arr= val.split(','); var v1 = toDecimal2(arr[0]);