Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a C++ Expert!

Join 415,731 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,925 people online right now.Registration is fast and FREE... Join Now!



converting double to system::string^ Rate Topic: -----

#1 bjones44  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-April 09


Dream Kudos: 0

Share |

converting double to system::string^

Post icon  Posted 08 April 2009 - 10:01 AM

Hello,

I have a double I would like to view in a textbox on button click, but i'm getting the following error "'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'double' to 'System::String ^'"

Is there any easy way to convert double to System::string^?

This is the code in my button click event.


textBox->Text = MyDouble;



Was This Post Helpful? 0
  • +
  • -


#2 JackOfAllTrades  Icon User is offline

  • Rama-llama-ding-dong
  • Icon

Reputation: 1532
  • View blog
  • Posts: 11,251
  • Joined: 23-August 08


Dream Kudos: 50

Expert In: Being annoyed with lazy people.

Re: converting double to system::string^

Posted 08 April 2009 - 10:03 AM

Doesn't ToString() work?
Was This Post Helpful? 0
  • +
  • -

#3 bjones44  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-April 09


Dream Kudos: 0

Re: converting double to system::string^

Posted 08 April 2009 - 10:12 AM

Textboxes don't seem to be capable of holding normal strings.

'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'std::string' to 'System::String ^'
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • while(sad){!sad; awesome();}
  • Icon

Reputation: 1294
  • View blog
  • Posts: 16,216
  • Joined: 14-September 07


Dream Kudos: 3150

Expert In: C, C++, Java

Re: converting double to system::string^

Posted 08 April 2009 - 10:24 AM

I'm not all that familiar with Visual C++/managed, but how about:

//make a System::String pointer
System::String^ str;
str = MyDouble.ToString(); //may need a & here, not entirely sure about ^ pointers

//pass str to the function


This post has been edited by KYA: 08 April 2009 - 10:26 AM

Was This Post Helpful? 0
  • +
  • -

#5 bjones44  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-April 09


Dream Kudos: 0

Re: converting double to system::string^

Posted 08 April 2009 - 10:54 AM

This works, thank you.
Was This Post Helpful? 0
  • +
  • -

#6 skymoon7  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 09


Dream Kudos: 0

Re: converting double to system::string^

Posted 19 May 2009 - 11:16 AM

I have the reverse problem, meaning that I need to convert a System::String ^ to double. Anyone, has an idea what should I do? I appreciate it.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Rama-llama-ding-dong
  • Icon

Reputation: 1532
  • View blog
  • Posts: 11,251
  • Joined: 23-August 08


Dream Kudos: 50

Expert In: Being annoyed with lazy people.

Re: converting double to system::string^

Posted 20 May 2009 - 06:14 AM

Double.TryParse() should help.
Was This Post Helpful? 0
  • +
  • -

#8 fluke  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-December 09


Dream Kudos: 0

Re: converting double to system::string^

Posted 11 December 2009 - 10:09 PM

View Postskymoon7, on 19 May, 2009 - 11:16 AM, said:

I have the reverse problem, meaning that I need to convert a System::String ^ to double. Anyone, has an idea what should I do? I appreciate it.

Example for a windows form, using one textBox and one label.
In the following, "huh" is a bool, "dubl" is a double:

// first check using TryParse if text converts to double from string
//true is returned if it converts
//also, it does the conversion and stores in variable "dubl".

  huh = double::TryParse(textBox1->Text, dubl);
               
            if(huh) // it converted sucessfully, use the value of "dubl"
	 { 
	   dubl *= 2.5; // mult dubl by 2.5 and store back in dubl
                     //display "dubl" in label1
	   label1->Text = dubl.ToString("###.00");  //2 dec points
	  }
	 else // "huh" not true, textbox was not a string convertible to double
                        // i.e. "1.23jkl"
	   {
                      label1->Text = "Not a number";
	    }


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 12 December 2009 - 06:43 AM

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users