function formatMoney(s, type) {
if (/[^0-9\.]/.test(s))
return "0";
if (s == null || s == "")
return "0";
s = s.toString().replace(/^(\d*)$/, "$1.");
s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
s = s.replace(".", ",");
var re = /(\d)(\d{3},)/;
while (re.test(s))
s = s.replace(re, "$1,$2");
s = s.replace(/,(\d\d)$/, ".$1");
if (type == 0) {
var a = s.split(".");
if (a[1] == "00") {
s = a[0];
}
}
return s;
}
var a = '123,456,789.55';
a = a.replace(/,/g,'');
a = parseFloat(a) + 100;
a = formatMoney(a, 0);
console.log(a);
var a = '123,533.80';
a = a.replace(/,/g,'');
a = parseFloat(a) + 100;
function formats(num) {
var rgx = /(\d+)(\d{3})/,
x1 = num + "";
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1
}
var newStr = formats(a.toFixed(2));
function add(str,num){
var str1=str.replace(/,/g,"");
var num1=parseFloat(str1)+num;
var arr=num1.toString().split(".");
function tho(x){
return x<1000?x:tho(parseInt(x/1000))+","+tho(String(x).slice(-3))
}
return tho(arr[0])+"."+arr[1]
}
console.log(add(a,100)//应该所有的加法都可以实现
var a = '123,456,789.55';