Heim > Fragen und Antworten > Hauptteil
三叔2016-11-09 10:46:48
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));
代言2016-11-09 10:46:33
var nums = '123,533.80'.split(','); nums[1] = (Number(nums[1])+100); nums.join(',');
三叔2016-11-09 10:46:18
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);