🔒 Locked
double to string ??
Advertisement
Original Post
iota() isn''t ANSI, only the char* → number conversion functions are.
In C, use sprintf().
In C++, use stringstream.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
In C, use sprintf().
In C++, use stringstream.
#include <sstream>
#include <string>
using namespace std;
int main()
{
stringstream ss;
double d = 415.234;
string str;
ss << d;
ss >> str;
}
#include <stdio.h>
int main()
{
char buf[256];
double d = 415.234;
snprintf( buf, 256, "%lf", d );
};
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
I don''t know of a function that converts a double to a string, but I''m sure someone must of made one. I''ve heard of a function for converting floats to strings; you can just convert the double to float, depending on how much accuracy you need. Maybe you should just search for dtoa() or ftoa() on a search engine. Good luck.
:::: Lektrix ::::
[ Google || ACCU || BarrysWorld || E-Mail Me ]
:::: Lektrix ::::
[ Google || ACCU || BarrysWorld || E-Mail Me ]
quote:
Original post by malpass
MSDN is never a help, I NEVER find what i''v after on there
But is that MSDN''s fault, or yours?
"The fact that a believer is happier than a skeptic is no more to the point than the fact that a drunken man is happier than a sober one." -- George Bernhard Shaw
double mydouble = 9.1234567
char* mystring;
sprintf(mystring, "%d", mydouble);
cout << mystring << endl;
---------------------------------------------------
"9.1234567"
-eldee
;another space monkey;
[ Forced Evolution Studios ]
char* mystring;
sprintf(mystring, "%d", mydouble);
cout << mystring << endl;
---------------------------------------------------
"9.1234567"
-eldee
;another space monkey;
[ Forced Evolution Studios ]

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!
all these are for converting double to string
1)ecvt() - Convert double to string of specified length
2)_fcvt() - Convert double to string with specified number of digits following decimal point
3)_gcvt() - Convert double number to string; store string in buffer
and if you want to makea float into a string then cast it to a double and use the above functions. You wont loose any precision that way.
I dont think the above functions are standard though. Search MSDN for parameter info.
:::Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile
1)ecvt() - Convert double to string of specified length
2)_fcvt() - Convert double to string with specified number of digits following decimal point
3)_gcvt() - Convert double number to string; store string in buffer
and if you want to makea float into a string then cast it to a double and use the above functions. You wont loose any precision that way.
I dont think the above functions are standard though. Search MSDN for parameter info.
:::Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement