摘要:數字轉千分位
- function cc(s) {//千分位显示
- if(isNaN(s)){//js自己的方法检验数字
- //alert(s+"2");
- document.getElementById("wrongText1").innerHTML="请输入正确的金额";
- return s;
- }
- else{
- //alert(s+"3");
- s=parseFloat(s);//去除首位输入的0,如002,小数不影响parseFloat字符串转数字
- //alert(s);
- s=s.toString();
- s = s.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");
- return s.replace(/^\./, "0.");
- document.getElementById("wrongText1").innerHTML="";
- }
- }
- function delcommafy(num){//去除千分位中的‘,’
- num=num.replace(/,/gi,'');
- return num;
- }