3

From managed C++, I am calling an unmanaged C++ method which returns a double. How can I convert this double into a managed string?

TylerH
  • 20,799
  • 66
  • 75
  • 101
stung
  • 347
  • 5
  • 13
  • 27

2 Answers2

7

I assume something like

(gcnew System::Double(d))->ToString()
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
DrPizza
  • 17,882
  • 7
  • 41
  • 53
  • Short and concised, thanks! Note: It should be (gcnew System::Double(d))->ToString() instead, but close enough. – stung Sep 19 '08 at 19:10
2

C++ is definitely not my strongest skillset. Misread the question, but this should convert to a std::string, not exactly what you are looking for though, but leaving it since it was the original post....

double d = 123.45;
std::ostringstream oss;
oss << d;
std::string s = oss.str();

This should convert to a managed string however..

double d = 123.45
String^ s = System::Convert::ToString(d);
Scott Nichols
  • 6,108
  • 4
  • 28
  • 23