CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Text-Box to Double conversion

    I've three textboxes I want to convert to Double.

    I don't know to use the IFormatProvider interface ...

    Code:
    				 // obtener los números desde el textbox
    				 IFormatProvider* ifp;
    				 Double a = A_coeff->Text->ToDouble(ifp);
    				 Double b = B_coeff->Text->ToDouble(ifp);
    				 Double c = C_coeff->Text->ToDouble(ifp);
    The problem is in ToDouble(ifp).. that's causing an exception.

    A_coeff, B_coeff and C_coeff are the textboxes.

    Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Seattle, WA
    Posts
    265
    Code:
    Double a = Double::Parse(A_coeff->Text);
    Double b = Double::Parse(B_coeff->Text);
    Double c = Double::Parse(C_coeff->Text);
    I'm new to C++ .NET so I don't know if this is right but it converts properly..
    "Lose it? It means go crazy...nuts...insane...bonzo...no longer in possession of one's faculties...3 fries short of a happy meal...WACKO!!!"

  3. #3
    Join Date
    Dec 2009
    Posts
    2

    Re: Text-Box to Double conversion

    Jinto, it seems that a newcomer is sometimes what is necessary to get a straight answer. Of course, if you are still visiting this site, you are not so new to .net now! Thanks.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Text-Box to Double conversion

    Parse is throwing an exception if the function fails. TryParse is not throwing.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Dec 2003
    Location
    India
    Posts
    17

    Thumbs up Re: Text-Box to Double conversion

    Hi ,

    If Parse is throwing an exception, then the problem is with the conversion,

    As for TryParse, it shall never throw an exception, as it returns a boolean value on succesful conversion.

    I suggest you use TryParse .

    Sujay

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