By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,819 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,819 IT Pros & Developers. It's quick & easy.

Double to String not working

P: 27
I'm trying to convert a double to a string and can't get it to work. I've tried Convert.ToString(...) and a few other permutations (System::Convert.ToString(...), etc), but nothing works. For some reason I keep getting back that Convert is not a part of the System namespace. Basically, the compiler can't recognize ToString() as a usable function. Any ideas on what's going wrong?
Mar 9 '07 #1
Share this Question
Share on Google+
12 Replies


100+
P: 1,646
If you are using c++ you can use sprintf()
Mar 9 '07 #2

sicarie
Expert Mod 2.5K+
P: 4,677
Yeah, do that.
Mar 9 '07 #3

P: 27
I've tried sprintf() and my doubles are being rounded. I'll go back and see what's going wrong there.

Any input on why Convert and ToString isn't working?
Mar 9 '07 #4

Expert 100+
P: 1,510
I've tried sprintf() and my doubles are being rounded. I'll go back and see what's going wrong there.

Any input on why Convert and ToString isn't working?
if you are using C++ you can functions in <sstream> to convert double, int, etc to a string, e.g.
Expand|Select|Wrap|Line Numbers
  1.     double pi = 3.14159;
  2.     ostringstream strout(ios_base::out);
  3.     strout << pi << endl;
  4.     cout << "pi as a string = " << strout.str() << endl;
  5.  
I have never heard of functions Convert and ToString in C/C++ - do you have a third party API?
Mar 9 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
I've tried sprintf() and my doubles are being rounded. I'll go back and see what's going wrong there.
And are you setting your precision when you use sprintf() (and it's still being rounded)?
Mar 9 '07 #6

100+
P: 1,646
I've tried sprintf() and my doubles are being rounded. I'll go back and see what's going wrong there.

Any input on why Convert and ToString isn't working?
You are using .net and getting confused with the different languages.
Mar 9 '07 #7

P: 27
Yes, I am. Sorry for any confusion. Should I repost the question in .net?
Mar 9 '07 #8

100+
P: 1,646
No. Following your thinking in this thread leads me to the conclusion that you will only confuse yourself doing that. We can get the answer together right here. First can you give us the following info?
What compiler are you using?
What language are you using?
Mar 9 '07 #9

P: 27
Ok. I'm using Borland Developer Studio and c++.
Mar 9 '07 #10

100+
P: 1,646
Great. sprintf() is part of the standard c++ library so it will work with your compiler. As for the precision problem you said you were having, you can control that with the format character. You can read all about sprintf() here.Good luck
Mar 9 '07 #11

P: 27
Thanks, it worked.
Mar 9 '07 #12

100+
P: 1,646
Thanks, it worked.
You are very welcome
Mar 10 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.