Archived

This topic is now archived and is closed to further replies.

LordG

How to convert a double to string in c++

Recommended Posts

_gcvt
Converts a floating-point value to a string, which it stores in a buffer.

char *_gcvt( double value, int digits, char *buffer );

Routine Required Header Compatibility
_gcvt Win 95, Win NT

Share this post


Link to post
Share on other sites
You could use sprintf(target string, format string, double value);

But I'm sure there are other ways, too.

Yeah, like that one

[edited by - Waverider on March 21, 2002 11:27:28 PM]

Share this post


Link to post
Share on other sites
How do I get rid of the padding zeros when converting a double to a string. For example, this code prints out 134.560000.


    
int main()
{
char str[20];
double x = 134.56;

sprintf(str, "%f", x);

cout << str << endl;

return 0;
}


[edited by - LordG on March 21, 2002 11:53:03 PM]

Share this post


Link to post
Share on other sites