locked
Convert Platform::String to float in C++ Windows store app

    Question

  • I just want to convert the content of a TextBox control (e.g. "25.0") to a float variable. I know in C# I can do it with System.Convert function. But how can I do it in a C++ Metro-style app?
    Saturday, October 27, 2012 4:49 PM

Answers

  • Get the String^'s Data buffer and use normal C++ methods such as wtof:

    	TextBox^ tb = safe_cast<TextBox^>(sender);
    	Platform::String^ s = tb->Text;
    	float f = _wtof(s->Data());
    

    --Rob
    Saturday, October 27, 2012 11:53 PM
    Owner

All replies