CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    [RESOLVED] How to get a float out of a textbox number ?

    Given a textbox containing the number (text) '123.234345456567', how do I get this converted to a float variable in the underlying c# code ?
    mpliam

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: How to get a float out of a textbox number ?

    Code:
    float f = float.Parse(TextBox1.Text);
    But this one will throw an exception if the input is not a valid float.
    Instead use
    Code:
    float f;
    bool valid = float.TryParse(TextBox1.Text, out f);

  3. #3
    Join Date
    May 2002
    Posts
    1,798

    Re: How to get a float out of a textbox number ?

    Thanks, Danny. I figured it out. See my previous post for an explanation of the problem I was having.

    http://www.codeguru.com/forum/showthread.php?t=509782

    mpliam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured