Thread: Check if user inserted value in a TextBox is a float

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Check if user inserted value in a TextBox is a float

    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by jmarcos View Post
    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.
    In what language?

    In C# you can use Parse or TryParse static method of Double
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Quote Originally Posted by jmarcos View Post
    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.
    In Windows programing, you can get the text from the textbox and later parse to see if there's a decimal dot inserted.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Thank for your replys. I'm programming in C++. The IDE is M. Visual Studio .NET 2008
    Joelito, do you suggest me to parse all the text inside the textbox and check if each character is a digit or the decimal character ("." or "," - depending on my Windows configurations)? I could only accept one decimal character. There is no other solution? Thanks. Joao

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by jmarcos View Post
    Thank for your replys. I'm programming in C++. The IDE is M. Visual Studio .NET 2008
    Joelito, do you suggest me to parse all the text inside the textbox and check if each character is a digit or the decimal character ("." or "," - depending on my Windows configurations)? I could only accept one decimal character. There is no other solution? Thanks. Joao
    you can use streamstream to convert the string to float and see the state and buffer of the stream after the operation
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    My IDE is Microsoft Visual Studio .NET and I'm programming in C++.

    I have solved my problem, as you can see below:

    Code:
    using namespace System;
    
    bool good_parsing = Double::TryParse(TextBox->Text, my_double_result_value);

  7. #7
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Quote Originally Posted by jmarcos View Post
    My IDE is Microsoft Visual Studio .NET and I'm programming in C++.

    I have solved my problem, as you can see below:

    Code:
    using namespace System;
    
    bool good_parsing = Double::TryParse(TextBox->Text, my_double_result_value);
    Ow, in C++ .NET...lolz
    I hate .NET, :P
    I though you mean in pure Win32 API
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to read a txt file into an array
    By Hitsugaya_KK in forum C Programming
    Replies: 49
    Last Post: 08-22-2009, 02:22 PM
  2. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 02:18 AM
  3. Need help with program
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 06-10-2007, 08:05 PM
  4. Multidimensional String
    By Beast() in forum C Programming
    Replies: 14
    Last Post: 07-03-2004, 12:47 AM
  5. Why does it work in Visual Studio and Not Borland
    By MonteMan in forum C++ Programming
    Replies: 14
    Last Post: 10-20-2002, 09:36 PM