Converting string to double

Posted on 2005-04-21
Last Modified: 2010-05-18
How does one convert a string from a text box and convert it to a double value or integer? Need to get a double number from a text box and assign it to a double argument.

double myVal;

txtBoxName->Text->ToDouble( myVal );

Question by:Mr_Crabs
    LVL 3

    Accepted Solution

    You can use the Double (Int32) Parse methods or the System.Convert class.
    LVL 3

    Expert Comment

    Try either atof(const char*) or atoi(const char*).

    So, you will get something like this:

    extern CEdit textBox;
    CString strText;
    double dVal = 0;
    textBox->GetLine(0, strText);
    dVal = atof(strText);

    Assuming the textBox is a CEdit ctrl declared somewhere in your code.

    Hope this helps,


    Author Comment

    double myVal;

    myVal = Convert::ToDouble( txtBoxNumber->Text );

    Oh, i did not understand all of that so I looked it up at msdn.
    It is also alot easier that what mactep13 suggested, whatever that was.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now