也就是可以转换成float型,3x!

解决方案 »

  1.   

    float.Parse(this.TextBox1.Text.Trim())
      

  2.   

    用Parse是比较精确的,用其他的本身具有强制转换功能,可能会造成数据和原来的不一样了。
      

  3.   

    private void textBox1_Leave(object sender, EventArgs e)
    {
        try
        {
             float.Parse(textBox1.Text.Trim());
         }
         catch
         {
              MessageBox.Show("请输入float");
              textBox1.Select();
         }
    }
      

  4.   

    我是想判断用户输入是否合法啊,否则会parse或convert出错
    难道必须用try catch 来确定用户输入是否是个float型吗??
      

  5.   

    using System.Text .RegularExpressions ;private void textBox1_Leave(object sender, System.EventArgs e)
    {
    string moban=@"^[+-]?\d+\.(\d)+$";
    if(!Regex .IsMatch (textBox1 .Text ,moban))
    MessageBox .Show ("please input float type!");

    }
      

  6.   

    不好意思,用的是日文vs,把里面的 钱的 符号斗换成 \ 就可以了using System.Text .RegularExpressions ;private void textBox1_Leave(object sender, System.EventArgs e)
    {
    string moban=@"^[+-]?\d+\.(\d)+$";
    if(!Regex .IsMatch (textBox1 .Text ,moban))
    MessageBox .Show ("please input float type!");

    }