C Board  

Go Back   C Board > General Programming Boards > FAQ Board

 
 
LinkBack Thread Tools Display Modes
Old 10-07-2001, 11:27 AM   #1
Registered User
 
Join Date: Sep 2001
Posts: 13
Question cout

Hello,

Could someone please tell me how to format data using cout?

For example, when using printf if I wanted to print out a floating point number to 2 decimal places I would do:

printf("%.2f",num);

Is it possible to do this using cout. The only way I have found is to use sprintf, and give cout the pointer. But surely there is a simpler way.

Thanks in advance.
evilmonkey is offline  
Old 10-07-2001, 11:32 AM   #2
Has a Masters in B.S.
 
Join Date: Aug 2001
Posts: 2,267
cout.precision(3);
cout << 2.3456764 << endl;

should out : 2.34.

keep in mind precision specifies the number of significant digits, not the number of decimal places.
__________________
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
no-one is offline  
 

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wiki FAQ dwks General Discussions 192 04-29-2008 01:17 PM
Redirect FAQ... Queatrix General Discussions 21 05-21-2007 04:48 PM
printf vs cout RyeDunn C++ Programming 5 07-09-2002 04:26 PM
What's wrong with Micorsoft Visual C++? knave C++ Programming 9 10-04-2001 08:02 AM


All times are GMT -6. The time now is 01:52 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22