473,411 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Double to String not working

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
12 3810
willakawill
1,646 1GB
If you are using c++ you can use sprintf()
Mar 9 '07 #2
sicarie
4,677 Expert Mod 4TB
Yeah, do that.
Mar 9 '07 #3
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
horace1
1,510 Expert 1GB
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
4,677 Expert Mod 4TB
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
willakawill
1,646 1GB
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
Yes, I am. Sorry for any confusion. Should I repost the question in .net?
Mar 9 '07 #8
willakawill
1,646 1GB
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
Ok. I'm using Borland Developer Studio and c++.
Mar 9 '07 #10
willakawill
1,646 1GB
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
Thanks, it worked.
Mar 9 '07 #12
willakawill
1,646 1GB
Thanks, it worked.
You are very welcome
Mar 10 '07 #13

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

Similar topics

2
by: Jon Maz | last post by:
Hi, I have written a page to test a function of mine that strips non-English accents and various other characters out of a given string. The function itself (called 'StripAll' in the code below)...
14
by: Lyle Fairfield | last post by:
d1 and d2 are numbers we can store as doubles (8 bytes). d1 > 0 d2 > 0 d1 < d2 Now s1 and s2 are strings of length 8 bytes. (We can ignore unicode here). Into s1 and s2 we copy the 8 bytes...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
12
by: Brett Hofer | last post by:
I must be missing something - Im a veteran C++ programmer now working with C# overall I like the language but find many weird changes... Anyway Im writing code behind an aspx. In this one C#...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
1
by: bsmith1111 | last post by:
I have a program that outputs the following to the screen (through visual c++) 9999999999, which is stored in a double. I would like to keep the number the way it is, but every time I output it...
5
by: lcw1964 | last post by:
Greetings again, I will burden the group with yet another tenderfoot question, but since conscientious googling hasn't yield a lucid answer I thought I would risk the shortcut of asking here...
5
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction>...
17
by: Terry | last post by:
I have some old VB5 functions that specify types of Long and Double that make calls to an unmanaged 3rd party DLL probably just as old. The source for the DLL is not available. I'm getting some...
3
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, I would like to convert a double to a string and have the resulting string contain all of the original values after the decimal place. Currently, the problem that I am having is that the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.