textBox中输入的字符为数值型 非正则方法

来源:互联网 发布:淘宝详情页还要切片吗? 编辑:程序博客网 时间:2024/05/21 18:41

try{  
      Convert.ToInt(ctl.Text);  
      //是数值型  
  }  
  catch(FormatException)  
  {  
      //非数值型  
  }

 

 try
            {
                double d = double.Parse(this.textBox1.Text.Trim());


                double a, equala;
                //equala的值为文本框中的值
                equala = Convert.ToDouble(this.textBox1.Text.ToString());

                //将a的小数部分舍去 
                a = Math.Truncate(equala);

                //定义c  c的值用来存 equala 与 a 的差
                double c;
                c = equala - a;


                if (c >= 0.5)
                {
                    a = a + 0.5;

                    Form3 f3 = new Form3();
                    f3.Show();
                }
                else
                {
                    equala = Math.Truncate(a);

                    Form2 f2 = new Form2();
                    f2.Show();
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show("输入有误:输入的字符不是数字型!", "请正确输入数字!");
                this.textBox1.Text = "";
               
            } 

原创粉丝点击