Jump to content
  • Advertisement

Archived

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

LordG

How to convert a double to string in c++

This topic is 5968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
_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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!