Very stupid question part 2

G

Guest

Thanks Folks,

Now I need to go the other way. That is, have a textBox display a
representation of a double precision number. I have tried (amoung other
things):

textBox2->Text=F.ToString;


all resulting in errors unintelegible by me.
 
N

Nathan Mates

Now I need to go the other way. That is, have a textBox display a
representation of a double precision number. I have tried (amoung other
things):
textBox2->Text=F.ToString;

Once again, the tried and true method in C/C++ is sprintf.
Don't knock it until you've tried it. For example:

char tempStr[128];
sprintf_s(tempStr, "%g", value);

Simple, portable (well, except for the _s part), and has more
possible options than you can shake a stick at.

Nathan Mates
 
C

Cholo Lennon

If you want a C++ way (and not C (like Nathan Mates' solution) or .Net way), you can use stringstream or wstringstream (sprintf is
faster but is not type safe). See interpret_cast in Kevlin Henney's paper (Valued Conversions,
http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf). Also see lexical_cast (from the same author) in boost
libraries for an updated and more complete version of interpret_cast (http://www.boost.org/libs/conversion/lexical_cast.htm). These
converter templates are very flexible, simple and useful.


Regards
 
B

Ben Voigt

mark said:
Thanks Folks,

Now I need to go the other way. That is, have a textBox display a
representation of a double precision number. I have tried (amoung other
things):

textBox2->Text=F.ToString;

ToString is a function, not a property. The () are not optional in C++.
textBox2->Text=F.ToString();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top