//n代表保留小数的个数 (0为还原) w:是否允许负数
function formatAmountValue(s, n, w) {
if (s == null) {
return "0.00";
}
if (n == 0) {// n==0 为还原操作
var bool = true;
while (bool) {
s = s.toString().replace(",", "");
if (s.indexOf(",") < 0) {
bool = false;
}
}
if (isNaN(s)) {
return "0.00";
}
return s;
}
if (typeof (s) == 'undefined') {
return '0.00';
}
if (isNaN(s) || s == "") {
return '0.00';
}
if (!w) {
if (s < 0) {
return '0.00';
}
}
if (s.length > 13) {
s = s.toString().substring(0, 12);
}
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^d.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
t = "";
for (i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r;
}
parseFloat转数字类型
$('#test').html(formatAmountValue(parseFloat($('#taxAmount_'+num).val()) +parseFloat( amount),2));










