446,134 Members | 1,796 Online
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

# How can i have the output in double digits

 P: 4 Hey... im new to c++ and im trying to write a program but am having difficulty trying to figure out how i can make my output have double digets even when it is 8 eg be 08. i think its got somthing to do with a combination of setw, setfill and setprecision. Please Help someone! Laura Mar 19 '07 #1
7 Replies

 Expert 100+ P: 1,510 Hey... im new to c++ and im trying to write a program but am having difficulty trying to figure out how i can make my output have double digets even when it is 8 eg be 08. i think its got somthing to do with a combination of setw, setfill and setprecision. Please Help someone! Laura try Expand|Select|Wrap|Line Numbers     int i=8;     cout << setfill('0') << setw(2) << i << endl; Mar 19 '07 #2

 P: 4 what about if it is for calculating time... say for instance i get this... 3:4:24.2 but i need 03:04:24.2? sorry im really bad atm.. iv only started learning! Mar 19 '07 #3

 Expert 100+ P: 1,510 what about if it is for calculating time... say for instance i get this... 3:4:24.2 but i need 03:04:24.2? sorry im really bad atm.. iv only started learning! once you setfill() it is fixed until you change it, you have to use setw() before each variable to be printed. Mar 19 '07 #4

 P: 4 ok that work... but it doesnt when i have a decimal! Mar 19 '07 #5

 Expert 100+ P: 1,510 ok that work... but it doesnt when i have a decimal! give an example of your problem? Mar 19 '07 #6

 P: 4 speeds: 3.9 38.2 18.6 distances: 0.4 10 2.5 time: 00:06:09.2 time : 00:15:42.4 time : 00:08:03.9 Total time : 00:29:55.5 but i dont know how to get the last digets to be 09.2 or 03.9 Mar 19 '07 #7

 Expert 100+ P: 1,510 try Expand|Select|Wrap|Line Numbers     float x=9.2;     cout << setfill('0') << setw(4) << x << endl;   Mar 19 '07 #8