function fmoney(s, nmoney(s, nmoney(s, nmoney(s, nmoney(s, nmoney(s, nmoney(s) { n = n > 0 && n s = parseFloat((s "").replace(/[^d.-]/g, "")).toFixed(n ) ""; var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1]; t = ""; for (i = 0; i t = l[i] ((i 1) % 3 == 0 && (i 1) != l. length ? "," : ""); } return t.split("").reverse().join("") "." r; }
/* * formatMoney(s,type) * 功能:金額以千位逗號分割 * 參數:s,需要格式化的金額數值. * 參數:type,判斷格式化後的金額是否需要小數位. * 回傳:傳回格式化後的數值字串. */ 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*.dd)d*/ , "$1"); s = s.replace(".", ","); var re = /(d)(d{3},)/; while (re. test(s)) s = s.replace(re, "$1,$2"); s = s.replace(/,(dd)$/, ".$1"); if (type == 0) {// 不帶小數位(預設為小數位) var a = s.split("."); if (a[1] == "00") { s = a[0]; } } return s; } /* * 通用DateAdd(interval,number,date) 功能:實作javascript的日期相加功能. * 參數:interval,字串表達式,表示要新增的時間間隔. 參數:number,數值表達式,表示要新增的時間間隔的個數. 參數:date,時間物件. * 回傳:新的時間物件. var now = new Date(); var newDate = DateAdd("day",5,now); * author:devinhua(從○開始) update:2010 -5-5 20:35 */ function DateAdd(interval, number, date) { if (date == null) return ""; switch (interval) { case "day": date = new Date(date); date = date.valueOf(); date = number * 24 * 60 * 60 * 1000 date = new Date(date); return date; break; default: return ""; break; } }