Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   number of decimal places (http://www.velocityreviews.com/forums/t288288-number-of-decimal-places.html)

shez 01-20-2005 03:04 AM

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-


shez 01-20-2005 03:11 AM

Re: number of decimal places
 
Sorry guys, i've found the answer. Pls ignore.

Sorry,
-shez-


Ulrich Achleitner 01-20-2005 08:03 AM

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

shez 01-20-2005 11:40 AM

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-


saurabh.unercat 02-19-2011 06:09 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57