Jump to content
  • Advertisement

Archived

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

Austrian Coder

double format

This topic is 5532 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

Hi! I have double b = 0.1; is there a function, which adds me an 0 to b? b = 0.10 I know it sounds silly. But i have an simple math programm (learning simple math stuff with computer). And I need an output with two decimal figure. I save two numbers in an stringstream and then return the string: stream << a << " " << b << " | "; Christian

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by RuneLancer
I''m going to get chewed on for this...
Indeed: the header should be <cstdio>, and you''ll want to call ios::sync_with_stdio(); somewhere.

Share this post


Link to post
Share on other sites
Here are two solutions which i found:
1.
stream << std::setprecision(2) << std::fixed << b;

2.
stringstream stream;
stream.precision(2);
stream.setf(ios_base::fixed,ios_base::floatfield);
stream << b;

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!