By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

number of decimal places

P: n/a
Hi,

Is there any way to output a double value with different number of
decimal places (apart from using 'sprintf'). I looked up the reference
for C++ streams and found the 'setprecision' manipulator, but this sets
the number of digits before and after the decimal point. I can't seem
to find any manipulator for setting the number of digits after the
decimal point.

Thanks,
-shez-

Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sorry guys, i've found the answer. Pls ignore.

Sorry,
-shez-

Jul 22 '05 #2

P: n/a
On 19 Jan 2005 19:11:42 -0800, shez <sh************@gmail.com> wrote:
Sorry guys, i've found the answer. Pls ignore.


you would not need to be sorry, if you were so kind to post the answer you
have found - perhaps others are interested, too.

ps: ignoring, as you suggest, is not possible, because to do so, anybody
must read your original posting, plus your answer to it...

--
have a nice day
ulrich
Jul 22 '05 #3

P: n/a
> you would not need to be sorry, if you were so kind to post the
answer you
have found - perhaps others are interested, too.


You can use the 'std::fixed' manipulator before setprecision, like
this:

std::cout << std::fixed << std::setprecision(2) << 1.2345678 <<
std::endl;

This should print to two decimal places. Thanks, -shez-

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.