![]() |
number of decimal places
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- |
Re: number of decimal places
Sorry guys, i've found the answer. Pls ignore.
Sorry, -shez- |
Re: number of decimal places
On 19 Jan 2005 19:11:42 -0800, shez <shezanbaig2004@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 |
Re: number of decimal places
> 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- |
the above codes work for the newr compilers...if any of you are luking fr things that work with <xyz.h> files only...use the setf as follows
cout.setf(ios::fixed); cout<<setprecision(4)<<number; ..//this prints exactly 4 digits after a decimal point :D |
| All times are GMT. The time now is 12:02 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.