Archived

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

Austrian Coder

double format

Recommended Posts

Austrian Coder    122
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
Beer Hunter    712
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
Austrian Coder    122
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