如题~!

解决方案 »

  1.   

    decimal.ToString("###,###,###.###0");
    decimal是你数据类型,括号里的参数根据你的需要可以自己改改。
      

  2.   

    在TextChange或者onkeydown事件里边改
    (比如textbox叫a)a.text = (system.convert.todecimal(a.text)).Tostring("###,###,###.###0");
      

  3.   

    简单的写了一个,看看符合要求不    <script type="text/javascript">
        var flag=0;
        function c()
        {
            var obj=document.getElementById("TextBox1");
            var v=obj.value;
            var l=v.length;
            if(l%4==0 && flag==0)
            {
                flag=1;
                obj.value=v.substring(0,l-3) + "," + v.substring(l-3,l);
            }
            else
            {
                flag=0;
            }
        }
        </script>    <asp:TextBox ID="TextBox1" onpropertychange="c()" runat="server"></asp:TextBox>
      

  4.   

    找到一个答案:
    http://topic.csdn.net/t/20040907/13/3348056.html
      

  5.   

        public string Commas(int nNum)
        {
            string str = nNum.ToString();
            int nIndex = str.Length;
            while (nIndex > 3)
            {
                str = str.Insert(nIndex - 3, ",");
                nIndex -= 3;
            }
            return str;
        }
      

  6.   

    呵,我刚做了测试
    <script language=javascript>
    function FormatNum(number,pattern)
    {
    代码内容请见http://topic.csdn.net/t/20040907/13/3348056.html
    }
    function showResult()
    {
        var num=document.getElementById("Text1").value.replace(/,/g,"");
        document.getElementById("Text1").value=FormatNum(num,'#,###');
    }
    </script><input id="Text1" type="text" onfocusout="showResult()" />
    测试后结果正确
      

  7.   

    上面写的好像不对,试试这个    function c()
        {
            var obj=document.getElementById("TextBox1");
            var v=obj.value;
            var leftValue;
            var temp='';
            var len;
            v=v.replace(/,/g,"");
            document.getElementById("Text1").value=v;
            len=v.length;
            if(len>3 && flag==0)
            {
                flag=1;
                while(len>3)
                {
                    leftValue=v.substring(0,len-3);
                    alert(leftValue);
                    temp="," + v.substring(len-3,len)+temp;
                    v=leftValue;
                    len = v.length;
                }
                obj.value=v+temp;
                temp='';
                flag=0;
            }
        }
      

  8.   

    现在程序员的思路真让我无语...
    先format(1222222.34444,"##,##0")处理整数部分
    然后处理小数部分,不就是千分位加一个逗号吗...
      

  9.   

    客户端的代码:
      <script type="text/javascript">
      <!--
    function aa(v)
    {
    var len=String(parseInt(v)).length;
    while(len>3)
    {

    v=v.substr(0, len-3)+','+v.substr(len-3);
    len=len-3;
    }
    return v;
    }
      //-->
      </script><input type="text" onblur="this.value=aa(this.value)" />
      

  10.   

    不防参考一下:
     decimal dec = 1234567890M;
            string newValue = string.Format("{0:N}", dec);
      

  11.   

    好像还是有问题,汗。。    function c()
        {
            var obj=document.getElementById("TextBox1");
            var v=obj.value;
            var leftValue;
            var temp='';
            var len;
            v=v.replace(/,/g,"");
            len=v.length;
            if(len>3 && flag==0)
            {
                flag=1;
                while(len>3)
                {
                    leftValue=v.substring(0,len-3);
                    temp="," + v.substring(len-3,len)+temp;
                    v=leftValue;
                    len = v.length;
                }
                obj.value=v+temp;
                temp='';
                flag=0;
            }
        }
      

  12.   

    13楼代码正解。
    这种情况用 javascript 好一点。还用.net里边的东西就有点绕道了。弄了变天.net也是用script来实现。还不如直接用javascript解决。
      

  13.   

    在TextChange或者onkeydown事件里边改 
    (比如textbox叫a) a.text = (system.convert.todecimal(a.text)).Tostring("###,###,###.###0");
      

  14.   

    decimal.ToString("★★★,★★★,★★★.★★★0"); 
      

  15.   

     格式化文本框输入每3位数字一个逗号
    http://www.aspxboy.com/private/showthread.asp?threadid=754
      

  16.   

    复杂的,但又通用的,其中有你要的代码://将数字格式化输出的javascript函数   
      function   FormatNum(number,pattern)   
      {   
      //alert("sdasd");   
      var   str =   number.toString();   
      var   strInt;   
      var   strFloat;   
      var   formatInt;   
      var   formatFloat;   
      if(/\./g.test(pattern))   
      {   
      formatInt =   pattern.split('.')[0];   
      formatFloat =   pattern.split('.')[1];   
      }   
      else   
      {   
      formatInt =   pattern;   
      formatFloat =   null;   
      }   
        
      if(/\./g.test(str))   
      {   
      if(formatFloat!=null)   
      {   
      var   tempFloat =   Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);   
      strInt =   (Math.floor(number)+Math.floor(tempFloat)).toString();   
      strFloat =   /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';   
      }   
      else   
      {   
      strInt =   Math.round(number).toString();   
      strFloat =   '0';   
      }   
      }   
      else   
      {   
      strInt =   str;   
      strFloat =   '0';   
      }   
      if(formatInt!=null)   
      {   
      var   outputInt =   '';   
      var   zero =   formatInt.match(/0*$/)[0].length;   
      var   comma =   null;   
      if(/,/g.test(formatInt))   
      {   
      comma =   formatInt.match(/,[^,]*/)[0].length-1;   
      }   
      var   newReg =   new   RegExp('(\\d{'+comma+'})','g');   
        
      if(strInt.length<zero)   
      {   
      outputInt =   new   Array(zero+1).join('0')+strInt;   
      outputInt =   outputInt.substr(outputInt.length-zero,zero)   
      }   
      else   
      {   
      outputInt =   strInt;   
      }   
        
      var     
      outputInt =   outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')   
      outputInt =   outputInt.replace(/^,/,'');   
        
      strInt =   outputInt;   
      }   
        
      if(formatFloat!=null)   
      {   
      var   outputFloat =   '';   
      var   zero =   formatFloat.match(/^0*/)[0].length;   
        
      if(strFloat.length<zero)   
      {   
      outputFloat =   strFloat+new   Array(zero+1).join('0');   
      //outputFloat =   outputFloat.substring(0,formatFloat.length);   
      var   outputFloat1 =   outputFloat.substring(0,zero);   
      var   outputFloat2 =   outputFloat.substring(zero,formatFloat.length);   
      outputFloat =   outputFloat1+outputFloat2.replace(/0*$/,'');   
      }   
      else   
      {   
      outputFloat =   strFloat.substring(0,formatFloat.length);   
      }   
        
      strFloat =   outputFloat;   
      }   
      else   
      {   
      if(pattern!=''   ||   (pattern==''   &&   strFloat=='0'))   
      {   
      strFloat =   '';   
      }   
      }   
        
      return   strInt+(strFloat==''?'':'.'+strFloat);   
        
        
      }   
      //         示例   
      //         alert(formatNum(0,''));   
      //         alert(formatNum(12432.21,'#,###'));   
      //         alert(formatNum(12432.21,'#,###.000#'));   
      //         alert(formatNum(12432,'#,###.00'));   
      //         alert(formatNum(12432.419,'#,###.0#'));   
          ///////////////////////////////////////////////////////